Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I am having an issue i have a Customers.xml file in which there is details of customer including userid and password.
Now i want to show only those data of which userid and password matched from xml file. Now i am able to find data if it is there in xml but when i am biding it to gridview it is showing complete xml data which i dont want. So how to do that?
Below is my button code:

C#
protected void Button1_Click(object sender, EventArgs e)
{
    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
    doc.Load(Server.MapPath("~/Customers.xml"));
    System.Xml.XmlNode usernameNode = doc.SelectSingleNode("/Customers/Customer/CustomerID");
    string username = usernameNode.InnerText;
    System.Xml.XmlNode passwordNode = doc.SelectSingleNode("/Customers/Customer/Password");
    string password = passwordNode.InnerText;
    if (TextBox1.Text == username && TextBox2.Text == password)
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath("~/Customers.xml"));
        GridView1.DataSource = ds;
        GridView1.DataBind();
        Label1.Text = "User found";
    }
    else
    {
        Label1.Text = "User Not found";
    }
    
}
Posted
Updated 14-Oct-14 20:39pm
v2
Comments
Samatha Reddy G 15-Oct-14 2:18am    
can you please provide your xml file?

1 solution

If you look into the BindingSource class[^] you can bind the DataSet to a BindingSource and then use the BindingSource as the data source of the GridView.

The BindingSource has a Filter[^] property that can be used to show only the rows in the underlying DataTable that matches the filter expression.

The examples in MSDN are pretty good.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900