Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GridView paging : beginner problem

Status
Not open for further replies.

Firecat1970

IS-IT--Management
May 25, 2003
68
0
0
HK
Dear experts,

On my page, I have a button and a GridView.
When I press the button, the GridView is shown with the data, however the page feature does not work, if I press the 2nd or 3rd page, the GridView disappear....

However, if I move the btnCode_OnClick context to Page_Load, then the page feature of the GridView is working properly...

What have I missed? How can I make GridView perform properly when its datasource is bind at runtime conditionally?

Thanks!

public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnCode_Click(object sender, ImageClickEventArgs e)
{
int nCount;
TList<Customers> CustomerList = new TList<Customers>();
CustomersService CustomerService = new CustomersService();
CustomerList = CustomerService.GetPaged(out nCount);
gvResult.DataSource = CustomerList;
gvResult.DataBind();
}
protected void gvResultOnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvResult.PageIndex = e.NewPageIndex;
gvResult.DataBind();
}
}
 
Sorry, I solved it... by changing OnPageIndexChanging

protected void gvResultOnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
int nCount;
TList<Customers> CustomerList = new TList<Customers>();
CustomersService CustomerService = new CustomersService();
CustomerList = CustomerService.GetPaged(out nCount);
gvResult.DataSource = CustomerList;

gvResult.PageIndex = e.NewPageIndex;
gvResult.DataBind();
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top