Now I am not able to do pagination. Please help
This is my Code
GridView.cs
protected void Page_Load(object sender, EventArgs e)
{
Getdata();
}
public void Getdata()
{
SqlConnection con = new SqlConnection("Data Source=CMH-SOSQL\\SQ1;Initial Catalog=RPT2020_DEV;Integrated Security=True");
con.Open();
string qry = "use PID2020_DEV select * from batch_void_rsn_cd";
SqlDataAdapter da = new SqlDataAdapter(qry, con);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView1.Columns[0].HeaderText = "First Row";
Label lblKey = (Label)e.Row.FindControl("Label1");
lblKey.Text = e.Row.RowIndex.ToString();
}
}
protected void GridView1_DataBound(object sender, EventArgs e)
{
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Getdata();
}
sampath kumarPosted May 4, 2013, 7:57 AM
lblKey.Text = e.Row.RowIndex.ToString();
In the above line, RowIndex should not be used directly, instead calculate the row index based on the PageIndex of the grid view.