Hi Waghmare,
Check this sample now please take its reference and correct your code.
HTML
<asp:GridView runat="server" ID="gvData" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="URL" HeaderText="URL" />
</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.Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("URL", typeof(string));
dt.Rows.Add(1, "Rohit", "Ro.com");
dt.Rows.Add(2, "John", "Jo.com");
dt.Rows.Add(3, "Smith", "Sm.com");
string GetId = "1,2";
DataSet dsMain = new DataSet();
dsMain.Tables.Add(dt);
DataRow[] result = dsMain.Tables[0].Select("ID IN (" + GetId + ")");
if (result.Length > 0)
{
this.gvData.DataSource = result.CopyToDataTable();
this.gvData.DataBind();
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.Page.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.Add("ID", GetType(Integer))
dt.Columns.Add("Name", GetType(String))
dt.Columns.Add("URL", GetType(String))
dt.Rows.Add(1, "Rohit", "Ro.com")
dt.Rows.Add(2, "John", "Jo.com")
dt.Rows.Add(3, "Smith", "Sm.com")
Dim GetId As String = "1,2"
Dim dsMain As DataSet = New DataSet()
dsMain.Tables.Add(dt)
Dim result As DataRow() = dsMain.Tables(0).Select("ID IN (" & GetId & ")")
If result.Length > 0 Then
Me.gvData.DataSource = result.CopyToDataTable()
Me.gvData.DataBind()
End If
End If
End Sub
Screenshot