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,

Recommended Answers

All 3 Replies

hi there
just post exact exception being thrown...

you have to write page indexing event for your gridview

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();
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.