asp.net - Pagination not working in asp:DataGrid -
problem:
when attempt go page 2 or other subsequent page of data grid, nothing refresh page.
markup:
<!--main datagrid--> <asp:datagrid id="dgtasks" runat="server" pagesize="40" allowpaging="true" autogeneratecolumns="false" forecolor="#333333" gridlines="both" font-size="small" allowsorting="true" onitemdatabound="item_databound" > <headerstyle backcolor="#990000" font-bold="true" forecolor="white" horizontalalign="center" font-size="small"/> <columns> ... </columns> <selecteditemstyle backcolor="#ffcc66" font-bold="true" forecolor="navy" /> <pagerstyle backcolor="#cccccc" forecolor="#333333" horizontalalign="right" mode="numericpages" /> <alternatingitemstyle backcolor="white" /> <itemstyle backcolor="#fffbd6" forecolor="#333333" /> <footerstyle backcolor="#990000" font-bold="true" forecolor="white" /> </asp:datagrid>
code behind:
public sub page_load(byval sender object, byval e system.eventargs) handles me.load if ispostback 'donothing' else binddata("") end if end sub private sub binddata(byval strdisplaycompleted string, byval strsort string) dim taskdataset taskdataset = new taskdataset() dim dt datatable = taskdataset.getdata("n").tables(0) each dr datarow in dt.rows if dr.item(2).tostring().startswith("vacancy") dr.delete() end if next if strsort.length > 0 dt.defaultview.sort = strsort end if dgtasks.datasource = dt.defaultview dgtasks.databind() end sub private sub binddata(byval strsort string) binddata("n", strsort) end sub
now, i'm not close sure why pagination not working. have allowpaging
equal true, i'm not re-binding data on postback, i'm confused. great. thanks.
it doesn't appear binding datagrid control objectdatasource, entitydatasource automatically take care of paging you.
you need handle paging event gridview , reset page index yourself
i.e.
gridview.pageindex = e.newpageindex
(i not @ machine ide cant confirm syntactically correct right now)
Comments
Post a Comment