Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP.NET (Non-Forum Related)
 filtering datagrid acording to query
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

blackinwhite
Average Member

Turkey
657 Posts

Posted - 05 June 2005 :  05:56:23  Show Profile
I have written such a code in order to parse the attributes in a xml file. It works great.

But I want to filter content according to a parameter from the query.

For example, when I type like products.aspx?type=fruit, I want to show only products whose types are fruit.


How can i do it?

Sample XML file.


<NewDataSet>
 <product type="fruit" name="orange" pcode="100" />
 <product type="car" name="audi" pcode="0231" />
</NewDataSet>


Thanks in advance.

<%
dim xmldoc as XmlDocument = new XmlDocument() 
xmldoc.Load(Server.MapPath("products.xml")) 
dim xmlnodes as XmlNodeList = xmldoc.SelectNodes("NewDataSet/Product") 
DataGrid1.DataSource = xmlnodes  
DataGrid1.DataBind ()  
%>

 
<asp:DataGrid id="DataGrid1" AutoGenerateColumns="False" runat="server"> 
<Columns> 
     <asp:TemplateColumn HeaderText="ProductCode"> 
     <ItemTemplate> 
          <%#CType(Container.DataItem, System.Xml.XmlNode).Attributes("pcode").value%> 
     </ItemTemplate> 
     </asp:TemplateColumn> 
</Columns> 
</asp:DataGrid>

Edited by - blackinwhite on 05 June 2005 05:56:55

Ghostnetworks
New Member

95 Posts

Posted - 08 June 2005 :  14:16:30  Show Profile  Visit Ghostnetworks's Homepage
I think this topic might help you out.

Instead of loading the XML file directly as the source, first apply it to a DataView...
Then filter the DataView based on your query.

e.g.

Dim strQuery As String = Request.QueryString("type").ToString()

myView.RowFilter = "type = '"& strQuery &"'"

'Now you can apply it directly to your DataGrid

DataGrid1.DataSource = myView


Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000 Version 3.4.07