Hi tareq16278,
Please refer below sample.
XML
<?xml version="1.0" encoding="utf-8" ?>
<Customers>
<user Name="ss">
<id>sss</id>
<Country>sss</Country>
</user>
<user Name="ss">
<id>sss</id>
<Country>sss</Country>
</user>
<user Name="love">
<id>eee</id>
<Country>sdfsd</Country>
</user>
<user Name="asp net">
<id>love</id>
<Country>www</Country>
</user>
<user Name="asp net">
<id>love</id>
<Country>www</Country>
</user>
<user Name="34wer">
<id>rerer</id>
<Country>ww</Country>
</user>
<user Name="asp">
<id>me</id>
<Country>love</Country>
</user>
<user Name="asp">
<id>viw</id>
<Country>all</Country>
</user>
<user Name="asp">
<id>viw</id>
<Country>all</Country>
</user>
<user Name="asp">
<id>viw</id>
<Country>all</Country>
</user>
</Customers>
HTML
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" />
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
using (DataSet ds = new DataSet())
{
ds.ReadXml(Server.MapPath("~/XMLFile.xml"));
DataRow[] dr = ds.Tables["user"].AsEnumerable().Where(x => x["name"].ToString().StartsWith("asp")).ToArray();
if (dr.Length > 0)
{
gvCustomers.DataSource = dr.CopyToDataTable();
gvCustomers.DataBind();
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindGrid()
End If
End Sub
Private Sub BindGrid()
Using ds As DataSet = New DataSet()
ds.ReadXml(Server.MapPath("~/XMLFile.xml"))
Dim dr As DataRow() = ds.Tables("user").AsEnumerable().Where(Function(x) x("name").ToString().StartsWith("asp")).ToArray()
If dr.Length > 0 Then
gvCustomers.DataSource = dr.CopyToDataTable()
gvCustomers.DataBind()
End If
End Using
End Sub
Screenshot