Hi sureshMGR,
Check this example. Now please take its reference and correct your code.
Databases
Here I am making use of Microsoft's Northwind Database. The download and install instructions are provided in the following article.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="EmployeeId" HeaderText="EmployeeId" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
</Columns>
</asp:GridView>
Namespaces
C#
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
VB.Net
Imports System.Data.SqlClient
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
string SQLConfigSettings = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(SQLConfigSettings);
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter("Select EmployeeId,LastName,FirstName from Employees", sqlconn);
DataSet ds = new DataSet();
adapter.Fill(ds);
DataView dataView = ds.Tables[0].DefaultView;
dataView.RowFilter = "EmployeeID >= 1 AND EmployeeID<=5";
GridView1.DataSource = dataView;
GridView1.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim SQLConfigSettings As String = ConfigurationManager.ConnectionStrings("ConString").ConnectionString
Dim sqlconn As SqlConnection = New SqlConnection(SQLConfigSettings)
Dim dt As DataTable = New DataTable()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("Select EmployeeId,LastName,FirstName from Employees", sqlconn)
Dim ds As DataSet = New DataSet()
adapter.Fill(ds)
Dim dataView As DataView = ds.Tables(0).DefaultView
dataView.RowFilter = "EmployeeID >= 1 AND EmployeeID<=5"
GridView1.DataSource = dataView
GridView1.DataBind()
End Sub
Screenshot