Hello Sir,
Im trying to apply pagination in gridview, but when click on 2nd or 3rd page its showing no record found.
below is the code which im using
Please help
Thanks
DateTime from_date = Convert.ToDateTime(txt_fromdate.Text);
DateTime to_date = Convert.ToDateTime(txt_todate.Text);
SqlCommand cmd1 = new SqlCommand("select * from table where name= '" + DropDownList1.SelectedItem.Text + "' and date BETWEEN @fromDate AND @ToDate ORDER BY date asc", con);
cmd1.Parameters.AddWithValue("@fromDate", from_date);
cmd1.Parameters.AddWithValue("@ToDate", to_date);
using (SqlDataAdapter da = new SqlDataAdapter(cmd1))
{
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGrid();
}
public void BindGrid()
{
string staff_name = DropDownList1.SelectedItem.Text;
DateTime from_date = Convert.ToDateTime(txt_fromdate.Text);
DateTime to_date = Convert.ToDateTime(txt_todate.Text);
DataTable dt = new DataTable();
dt = obj_select.select_all_staff_alignment(staff_name,from_date,to_date);
GridView1.DataSource = dt; // give data to GridView
GridView1.DataBind();
con.Close();
}