Custom Pagin in GridView
Hello Friends,
I'm implementing custom paging in my GridView. Paging numbering(in-built paging numbering) does not display but it brings the records are queried . Below giving my code please let me know what changes i should make in my code. But if i use in-built paging(normal paging) then that's working fine......
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
lblMsg.Text = e.NewPageIndex.ToString();
int pageNumber=Convert.ToInt32(e.NewPageIndex);
int recordPerPage= 4;
int startRecord = (pageNumber) * recordPerPage + 1;
int maxRecord = startRecord + recordPerPage;
bindGridView1(startRecord,maxRecord);
}
public void bindGridView1(int startRecord,int maxRecord)
{
string connectionString = "server=.;database=Auto_New;uid=sa;pwd=;";
using(SqlConnection mCon = new SqlConnection(connectionString))
{
SqlCommand mDataCom = new SqlCommand();
mDataCom.Connection = mCon;
mDataCom.CommandType = CommandType.StoredProcedure;
mDataCom.CommandText = "SP_Select1";
mDataCom.Parameters.AddWithValue("@startRecord", startRecord);
mDataCom.Parameters.AddWithValue("@maxRecord", maxRecord);
SqlDataAdapter da = new SqlDataAdapter(mDataCom);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
}
|