473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

datagrid filter for specific record(s)

I want to display only data in the datagrid for specific records having a common or identical data in a column.
How do you do this programmaticaly using combination of the datagrid object, dataadapter, sqlconnection objects in the ide design?

The walkthrough "Walkthrough: Using a DataGrid Web Control to Read and Write Data" doesn't include this filter ofor specifc group of records.
Thanks in advance.
Nov 18 '05 #1
3 1769
When you bind a DataSet to a DataGrid, you are actually binding the default
view of the first table, if you do not specify. IE:

DataGrid1.DataSource = MyDataSet;

is equivalent to:

DataGrid1.DataSource = MyDataSet.Tables[0].DefaultView;

So, you can specify different views if you explicitly code. For example:

DataView MyDataView = new DataView(MyDataSet.Tables[0]);
MyDataView.Filter = "Country='USA'";

Now, only items with country equal to USA are displayed. You then bind to
DataGrid like so:

DataGrid1.DataSource = MyDataView;

In the help file, you can see a different constructor for the view. And, you
can create multiple views if you want different slices of the same data.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Pedor" <pe***@anonymous.net> wrote in message
news:E6**********************************@microsof t.com...
I want to display only data in the datagrid for specific records having a common or identical data in a column. How do you do this programmaticaly using combination of the datagrid object, dataadapter, sqlconnection objects in the ide design?
The walkthrough "Walkthrough: Using a DataGrid Web Control to Read and Write Data" doesn't include this filter ofor specifc group of records. Thanks in advance.

Nov 18 '05 #2
When you bind a DataSet to a DataGrid, you are actually binding the default
view of the first table, if you do not specify. IE:

DataGrid1.DataSource = MyDataSet;

is equivalent to:

DataGrid1.DataSource = MyDataSet.Tables[0].DefaultView;

So, you can specify different views if you explicitly code. For example:

DataView MyDataView = new DataView(MyDataSet.Tables[0]);
MyDataView.Filter = "Country='USA'";

Now, only items with country equal to USA are displayed. You then bind to
DataGrid like so:

DataGrid1.DataSource = MyDataView;

In the help file, you can see a different constructor for the view. And, you
can create multiple views if you want different slices of the same data.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Pedor" <pe***@anonymous.net> wrote in message
news:E6**********************************@microsof t.com...
I want to display only data in the datagrid for specific records having a common or identical data in a column. How do you do this programmaticaly using combination of the datagrid object, dataadapter, sqlconnection objects in the ide design?
The walkthrough "Walkthrough: Using a DataGrid Web Control to Read and Write Data" doesn't include this filter ofor specifc group of records. Thanks in advance.

Nov 18 '05 #3
I try to add/modify the codes below, but newbie me, just can't think of more ways to have it run well..
help me please thanks in advanc

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
'Put user code to initialize the page her
If Session("mydataset") Is Nothing Then
Me.SqlDataAdapter1.Fill(dsMyProject
Session("mydataset") = dsMyProjec
Els
dsMyProject = CType(Session("mydataset"), DataSet2
End I

If Not IsPostBack The
Me.DataGrid1.DataSource = "dsMyProject
Me.DataGrid1.DataKeyField = "devID
Me.DataGrid1.DataMember = "tblMyProject
Me.DataGrid1.DataBind(

'To filter datagrid for specific record(s)
'DataView MyDataView = new DataView(dsDevDev.tblDevDEV[0]); '<---- Cowboy's recommended lines t( to be modif
'MyDataView.Filter = "devID='2'"

End I

End Sub
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter | last post by:
In this topic "Walkthrough: Using a DataGrid Web Control to Read and Write Data" updates/edits of a table are covered for all data and column(s). However no topic or section dedicated to explain...
3
by: Tony Williams | last post by:
Sorry to repost but I cannot work this out. Can anyone come up with a suggestion? I have a main form based on Table1. The form has a tab control of three pages. Each page has a subform based on a...
1
by: Guy Noir | last post by:
I am having trouble wrapping my head around a datagrid and datasource. I have it working, sort-of, but I'm having trouble refreshing my views. Here's what I have: A dataAdapter and dataSet...
2
by: Mark Rae | last post by:
I've inherited an ASP.NET app and have been asked to fix the following problem with a page which is used to display and/or delete records from a database. When the page loads, it displays a list of...
2
by: Brad Shook | last post by:
First of all thinks to Cor Ligthert for helping me with this last week. If you wild like to read Cor's comments please refer to the posting from 10/14/2004 and 8:48AM "Help with Advanced...
9
by: John Hernry | last post by:
I have been watching the dotnet newsgroups for a couple of weeks now and scouring the net looking for a solution to my datagrid find functionality. With no luck. I am hoping that you can help me....
6
by: Doug Bell | last post by:
Hi I have a datagrid with a combo box, I need to populate the combo with data dependant on the record value. eg for record 1, field Warehouse = 2R so combo would allow selection of locations...
0
by: Dave | last post by:
I have a datagrid that populates with about 15 columns...and about 40 pages. On of the columns is called ProjNo. Is there a way for someone to type a value in a Textbox and on Postback have the...
3
by: franc sutherland | last post by:
Hello, I have a report which I filter using the me.filter command in the OnOpen event. Me.Filter = "OrderID=" & Forms!variable_form_name! Me.FilterOn = True I want to be able to open that...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.