select particular field from an xml file

Posted by Klbaiju under ASP.NET on 11/26/2010 | Points: 10 | Views : 1585 | Status : [Member] | Replies : 1
<Employees>
<Employee>
<Id>100</Id>
<Name>arun</Name>
<Dept>Electrical</Dept>
<dtdate>12-05-2010 </dtdate>
</Employee>
<Employee>
<Id>101</Id>
<Name>Aji</Name>
<Dept>Computer</Dept>
<dtdate>13-05-2010 </dtdate>
</Employee>
<Employee>
<Id>102</Id>
<Name>Kiran</Name>
<Dept>civil</Dept>
<dtdate>14-05-2010 </dtdate>
</Employee>

</Employees>
Hi, Friends i want to display the record of employee with Name="Kiran" in a gridview.
how it is possible.
.

Iam trying this method

DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("Employee.xml"));
foreach (DataRow dr in ds.Tables[0].Select("Name='Kiran'"))
{


GridView1.DataSource = ?;
GridView1.DataBind();


}

do u have any idea


Baiju




Responses

Posted by: T.saravanan on: 11/29/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Try this coding....


DataTable dtData = ds.Tables[0].Clone();
foreach (DataRow dr in ds.Tables[0].Select("Name='Kiran'"))
{
dtData.ImportRow(dr);
}
GridView1.DataSource = dtData.Copy();
GridView1.DataBind();


(or)

DataRow[ ] drRow;

DataTable dtData = ds.Tables[0].Clone();
drRow = ds.Tables[0].Select("Name='Kiran'")
if(drRow.Length > 0)
{
dtData = drRow.CopyToDataTable();
}
GridView1.DataSource = dtData.Copy();
GridView1.DataBind();


Cheers :)


Thanks,
T.Saravanan

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response