I have trouble to set last row for paging.
I set Page size: 10 in gridview
This my behind code:
protected void Page_Load(object sender, EventArgs e)
{
BindData();
}
public void BindData()
{
string strConnection = @"Data Source=.\sa;Initial Catalog=Northwind;Integrated Security=SSPI;";
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand cmd = new SqlCommand("select ProductId, ProductName, SupplierId from Products", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindData();
}
The Result:
but after I change page 7 to last page have only less than 10 rows.
I want the last page have 10 rows although data table 7 rows
anybody can improve my code.