c# - Asp .Net Gridview paging -
trying paging of grid.
<pagerstyle horizontalalign="right" cssclass="paging"/> <pagertemplate> <table width="100%"> <tr> <td style="text-align:left; width:50%"> <asp:linkbutton id="lnkprv" visible="false" commandname="page" commandargument="prev" runat="server">previous</asp:linkbutton> </td> <td style="text-align:right; width:50%;padding-left:50%;"> <asp:linkbutton id="lnknext" commandname="page" commandargument="next" runat="server">next</asp:linkbutton> </td> </tr> </table> </pagertemplate>
code behind below
protected void gvproduct_pageindexchanging(object sender, gridviewpageeventargs e) { literal1.visible = gvproduct.pageindex == 0; linkbutton lnkprv = (linkbutton)gvproduct.bottompagerrow.findcontrol("lnkprv"); linkbutton lnknext = (linkbutton)gvproduct.bottompagerrow.findcontrol("lnknext"); lnkprv.visible = e.newpageindex > 0; lnknext.visible = e.newpageindex < gvproduct.pagecount - 1; gvproduct.pageindex = e.newpageindex; fillgrid(); }
the code not give error. can see set visible property true/false. actual control on page remain same (always visible on every page). '
what wrong?
if fillgrid() method rebinding gvproduct (i.e. gvproduct.databind()) lnkprv , lnknext visible values going use defaults markup when databinding. need set visibility of these controls in event handler rowdatabound event of gvproduct.
protected void gvproduct_pageindexchanging(object sender, gridviewpageeventargs e) { literal1.visible = gvproduct.pageindex == 0; gvproduct.pageindex = e.newpageindex; fillgrid(); } protected void gvproduct_rowdatabound(object sender, gridviewroweventargs e) { if (e.row.rowtype == datacontrolrowtype.pager) { linkbutton lnkprv = (linkbutton)e.row.findcontrol("lnkprv"); linkbutton lnknext = (linkbutton)e.row.findcontrol("lnknext"); lnkprv.visible = gvproduct.pageindex > 0; lnknext.visible = gvproduct.pageindex < gvproduct.pagecount - 1; } }
Comments
Post a Comment