datagrid filter for specific record(s)

G

Guest

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.
 
C

Cowboy \(Gregory A. Beamer\)

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 said:
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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top