asp.net - Implementing pager control for gridview? -
is there way select number of records/rows display in gridview drop down list ?
you can use rowcreated create dropdownlist in codebehind. have @ following example(vb.net):
private sub yourgrid_rowcreated(byval sender object, byval e system.web.ui.webcontrols.gridviewroweventargs) handles yourgrid.rowcreated select case e.row.rowtype case datacontrolrowtype.pager dim ddlpager new dropdownlist ddlpager.id = "ddlpager" ddlpager.autopostback = true ddlpager.tooltip = "change pagesize" ddlpager.items.add("5") ddlpager.items.add("10") ddlpager.items.add("25") ddlpager.items.add("50") ddlpager.items.add("100") ddlpager.selectedvalue = "10" addhandler ddlpager.selectedindexchanged, addressof me.pagesizechanged e.row.cells(0).columnspan -= 1 dim td new tablecell dim span1 new label span1.text = "show" span1.style("margin-left") = "50px" td.controls.add(span1) td.controls.add(ddlpager) dim span2 new label span2.text = "rows per page" td.controls.add(span2) e.row.cells.add(td) end select end sub private sub pagesizechanged(byval sender object, byval e system.eventargs) dim ddlpager dropdownlist = directcast(sender, dropdownlist) dim newpagesize int32 = int32.parse(ddlpager.selectedvalue) yourgrid.pagesize = newpagesize 'change pagesize of grid' databindyourgrid() 'call function binds grid datasource' updyourgrid.update() 'if use ajax, update updatepanel of gridview' end sub
on way autogenerate dropdonwlist on every postback , add gridview's pager. code reusable gridview.
Comments
Post a Comment