Filter Records

S

shapper

Hello,

I have a GridView and I need to display only the records which field
in datasource named "visible" is set to true.

How can I do this?

Thanks,
Miguel
 
S

shapper

Create a DataView with RowFilter property set to "'visible'=true" and
databind the gridview to it.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net






I have a GridView and I need to display only the records which field
in datasource named "visible" is set to true.
How can I do this?
Thanks,
Miguel

And can I create two data views and use one or the other?

I just know how to use the default view

I am creating my data views as follows:
Dim dvLevels As New DataView(dtLevels, "LevelSubscribed = False",
"LevelName", DataViewRowState.CurrentRows)

Thanks,
Miguel
 
E

Eliyahu Goldin

Sure you can. Like you do in the code
Dim dvLevels As New DataView(dtLevels, "LevelSubscribed = False",
"LevelName", DataViewRowState.CurrentRows)

Just create another one similarly and databind to whatever is needed.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


shapper said:
Create a DataView with RowFilter property set to "'visible'=true" and
databind the gridview to it.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net






I have a GridView and I need to display only the records which field
in datasource named "visible" is set to true.
How can I do this?
Thanks,
Miguel

And can I create two data views and use one or the other?

I just know how to use the default view

I am creating my data views as follows:
Dim dvLevels As New DataView(dtLevels, "LevelSubscribed = False",
"LevelName", DataViewRowState.CurrentRows)

Thanks,
Miguel
 
D

David Longnecker

Shapper-

You mentioned that you are comfortable with the DefaultView DataView. As
Eilyahu mentioned, you can create additional DataViews as needed within your
applications. See below:

DataTable testData = GenFakeData(); // Generate our fake data.
testData.DefaultView.RowFilter = "Visible=true"; // Filter on our visible
column == true.
testGridView.DataSource = testData.DefaultView; // Set our GridView's datasource
to our filtered view.
testGridView.DataBind(); // bind.

This returns:

Group, Value, Visible
1, 3, true
1, 4, true
1, 5, true
2, 3, true
2, 4, true
2, 5, true

DataTable testData2 = GenFakeData(); // Generate our fake data.
DataView dv = new DataView(testData2); // Create a new dataview based on
our datatable.
dv.RowFilter = "Visible=false"; // Filter on our visible column == false.
testGridView2.DataSource = dv; // Set our GridView's datasource to our newly
created view.
testGridView2.DataBind(); // bind.

This returns:

Group, Value, Visible
1, 1, false
1, 2, false
2, 1, false
2, 2, false

HTH.

-dl


---
David Longnecker
Web Developer
http://blog.tiredstudent.com
Create a DataView with RowFilter property set to "'visible'=true" and
databind the gridview to it.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

Hello,

I have a GridView and I need to display only the records which field
in datasource named "visible" is set to true.

How can I do this?

Thanks,
Miguel
And can I create two data views and use one or the other?

I just know how to use the default view

I am creating my data views as follows:
Dim dvLevels As New DataView(dtLevels, "LevelSubscribed = False",
"LevelName", DataViewRowState.CurrentRows)
Thanks,
Miguel
 
S

shapper

Shapper-

You mentioned that you are comfortable with the DefaultView DataView. As
Eilyahu mentioned, you can create additional DataViews as needed within your
applications. See below:

DataTable testData = GenFakeData(); // Generate our fake data.
testData.DefaultView.RowFilter = "Visible=true"; // Filter on our visible
column == true.
testGridView.DataSource = testData.DefaultView; // Set our GridView's datasource
to our filtered view.
testGridView.DataBind(); // bind.

This returns:

Group, Value, Visible
1, 3, true
1, 4, true
1, 5, true
2, 3, true
2, 4, true
2, 5, true

DataTable testData2 = GenFakeData(); // Generate our fake data.
DataView dv = new DataView(testData2); // Create a new dataview based on
our datatable.
dv.RowFilter = "Visible=false"; // Filter on our visible column == false.
testGridView2.DataSource = dv; // Set our GridView's datasource to our newly
created view.
testGridView2.DataBind(); // bind.

This returns:

Group, Value, Visible
1, 1, false
1, 2, false
2, 1, false
2, 2, false

HTH.

-dl

---
David Longnecker
Web Developerhttp://blog.tiredstudent.com
Create a DataView with RowFilter property set to "'visible'=true" and
databind the gridview to it.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

Hello,
I have a GridView and I need to display only the records which field
in datasource named "visible" is set to true.
How can I do this?
Thanks,
Miguel
And can I create two data views and use one or the other?
I just know how to use the default view
I am creating my data views as follows:
Dim dvLevels As New DataView(dtLevels, "LevelSubscribed = False",
"LevelName", DataViewRowState.CurrentRows)
Thanks,
Miguel

Yes, I know. I had that.

My question was if I could access each view as follows:

DataTable.MyNewView

Instead of:

DataTable.DefaultView

Anyway, I got this now ...

Thanks,
Miguel
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top