0

hi..

im using a a gridview with template fields which contains labels to display the dynamic data from database..

my problem is, i want to use paging concept in the gridview. but as im using template fields & a dynamic database, im getting an error..

this is how im binding the labels with the data from the database.

ds = bl.Bind("Bind");
grdProducts.DataSource = ds.Tables[0];
grdProducts.DataBind(); //binds the database to grid.
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    //loop to bind the labels with the data from database
HyperLink chk2 =(HyperLink)(grdProducts.Rows[i].Cells[4].FindControl("hypName"));
Label id = (Label)(grdProducts.Rows[i].Cells[4].FindControl("lblPrId"));
if (chk2 != null)
{
   if (chk2.Text != "")
  {
  string name = ds.Tables[0].Rows[i][1].ToString();
  chk2.Text = name;
  chk2.NavigateUrl = "#";
    }
  }

 }
}

now if i set a page size of 10 & my datacount is say 60, then the it shows error when "i" reaches to 10.

then how can i achieve paging in such conditions?

Hoping for a response soon.

Thank you,

Edited by love_dude1984: n/a

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by mail2saion
0

Write the below handler for your GridView:

protected void gvEdit_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvEdit.PageIndex = e.NewPageIndex;
        DataTable dtSupplier = (DataTable)ViewState["dtSupplier"];
        gvEdit.DataSource = dtSupplier;
        gvEdit.DataBind();
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.