Filtering a Dataview -- Help Please

J

Jason

I've gathered a bunch of data from Active Directory and placed it into a
datatable ("ADTable"). I now need to sort and filter this table based on
the selection of a drop down list("ddlCategory"). How can I filter the
dataview of this datatable to display those records that match (partially or
fully) the value selected in the drop down list?

I have the following code that doesn't work, and returns zero rows (note
that 'department' is a valid column name as I've tested dvCustom.RowFilter
="department Like Information Management" and it works):

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

'Make a copy of the default dataview of the ADTable so it's refreshed to
original every time button is clicked.

Dim dvCustom As DataView = ADTable.DefaultView

dvCustom.RowFilter = "department LIKE " & "'*" &
ddlCategory.SelectedItem.Text & "*'"
'cn is another column name, is valid and works.
dvCustom.Sort = "cn"

'DGADResults is simply a datagrid that displays the dataview

DGADResults.DataSource = dvCustom
DGADResults.DataBind()
End Sub

Any help would be greatly appreciated!

Thanks in advance,

Jason
 
J

Jason

Thanks alot, that worked alot better than trying to create a custom filter
with wildcards, etc (which I did end up getting to work as well, but
disgarded for this simpler way).

Thanks again.


vzaffiro said:
Hey jason,

I have done this thru a datatable using the following logic
//Create the datatable from the dataset
DataTable dt = Common.GetLookupTable(table,webpage);

//Foundrows is an array that will be returned from the select
DataRow[] foundRows;

//Create the where clause
string whereclause = string.Format("cdstatus = {0} and cdstatus_apr_ord =
{1}",cdStatus,currentOrder)

//Fill the array by filtering the data table
foundRows = dt.Select(whereclause);

Foundrows now has an array of datarows that you can traverse.

Here are some references:
http://www.akadia.com/services/dotnet_filter_sort.html
http://www.eggheadcafe.com/articles/20030903.asp

Good Luck!

Jason said:
I've gathered a bunch of data from Active Directory and placed it into a
datatable ("ADTable"). I now need to sort and filter this table based on
the selection of a drop down list("ddlCategory"). How can I filter the
dataview of this datatable to display those records that match (partially or
fully) the value selected in the drop down list?

I have the following code that doesn't work, and returns zero rows (note
that 'department' is a valid column name as I've tested dvCustom.RowFilter
="department Like Information Management" and it works):

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

'Make a copy of the default dataview of the ADTable so it's refreshed to
original every time button is clicked.

Dim dvCustom As DataView = ADTable.DefaultView

dvCustom.RowFilter = "department LIKE " & "'*" &
ddlCategory.SelectedItem.Text & "*'"
'cn is another column name, is valid and works.
dvCustom.Sort = "cn"

'DGADResults is simply a datagrid that displays the dataview

DGADResults.DataSource = dvCustom
DGADResults.DataBind()
End Sub

Any help would be greatly appreciated!

Thanks in advance,

Jason
 

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,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top