I am using an xmldatasource to populate a data grid in vb.net/asp.net. I have a number of controls above my grid which I want to use to be able to filter the grid data.
I can do this fine for single controls using as an example:
However I want to be able to enter data in to multiple controls and filter based on these. My problem is also what to do when the control has nothing entered.. how would I ignore this control?
I have tried to solve this problem by doing the following:
Dim filtering As String
filtering = ""
If Me.DropDownList8.SelectedItem.Text = "All" Then
filtering = filtering
Else
filtering = "//*[@Asset_cost_centre='" & Me.DropDownList8.SelectedValue & "'] AND "
End If
If Len(Me.TextBox5.Text) > 0 Then
filtering = filtering & "//*[@Asset_Number='" & Me.TextBox5.Text & "'] AND "
Else
filtering = filtering
End If
If Len(Me.TextBox6.Text) > 0 Then
filtering = filtering & "//*[@Asset_descriptor='" & Me.TextBox6.Text & "'] AND "
Else
filtering = filtering
End If
If Len(filtering) > 0 Then
filtering = Left(filtering, Len(filtering) - 5)
Else
End If
Me.XmlDataSource5.XPath = filtering
Me.GridView1.PageIndex = 0
Me.GridView1.DataBind()
However it appears that just using an AND operator and trying to check if a control has a length etc does not produce valid results:
//*[@Asset_cost_centre='704231'] AND //*[@Asset_Number='15507']
aspmunkee
Member
6 Points
29 Posts
xpath filtering data in datagrid with xmldatasource multiple filters?
May 03, 2012 12:43 PM|LINK
Hi All,
I am using an xmldatasource to populate a data grid in vb.net/asp.net. I have a number of controls above my grid which I want to use to be able to filter the grid data.
I can do this fine for single controls using as an example:
However I want to be able to enter data in to multiple controls and filter based on these. My problem is also what to do when the control has nothing entered.. how would I ignore this control?
I have tried to solve this problem by doing the following:
Dim filtering As String filtering = "" If Me.DropDownList8.SelectedItem.Text = "All" Then filtering = filtering Else filtering = "//*[@Asset_cost_centre='" & Me.DropDownList8.SelectedValue & "'] AND " End If If Len(Me.TextBox5.Text) > 0 Then filtering = filtering & "//*[@Asset_Number='" & Me.TextBox5.Text & "'] AND " Else filtering = filtering End If If Len(Me.TextBox6.Text) > 0 Then filtering = filtering & "//*[@Asset_descriptor='" & Me.TextBox6.Text & "'] AND " Else filtering = filtering End If If Len(filtering) > 0 Then filtering = Left(filtering, Len(filtering) - 5) Else End If Me.XmlDataSource5.XPath = filtering Me.GridView1.PageIndex = 0 Me.GridView1.DataBind()However it appears that just using an AND operator and trying to check if a control has a length etc does not produce valid results:
Thanks for any help,
Chris
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: xpath filtering data in datagrid with xmldatasource multiple filters?
May 05, 2012 01:21 AM|LINK
Hello:)
As far as I see,I think you can change to another way by importing all of the records from the xml into DataTable by refering this:
DataSet ds = new DataSet(); ds.ReadXml("xxx.xml");and then with the help of DataView's RowFilter:
Or another way is that you can use Multiple-Filtering Control:
http://www.codeproject.com/Articles/26969/GridView-Multiple-Filter-AJAX-Control