In Coding Page
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
OnPageIndexChanging="GridView1_PageIndexChanging" OnSorting="GridView1_Sorting"
Style="z-index: 100; left: 315px; position: absolute; top: 106px">
asp:GridView>
Set Following GridView Properties
AllowPaging=True;
AllowSorting=True;
DatakeyNames=eno(set Primary Key colume name)
In .cs File
using System.Data.Odbc;
public partial class _Default : System.Web.UI.Page
{
string str;
OdbcConnection myConn = new OdbcConnection("driver={Mysql odbc 3.51 driver};user id=root;password=admin;server=localhost;database=temp");
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
str = "select * from emp1";
getdata(str);
}
}
public void getdata(string s)
{
OdbcDataAdapter da = new OdbcDataAdapter(s, myConn);
DataSet ds = new DataSet();
da.Fill(ds, "raji");
GridView1.DataSource = ds;
GridView1.DataBind();
}
//in gridview PageIndexChanging event
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
getdata("select * from emp1");
}
//in gridview Sorting event
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
str = "select * from emp1 order by " + e.SortExpression;
getdata(str);
}
}
0 comments:
Respects for your's Questions & Opinions