i want paging in repeater control. using xml database linq. please give me suggestion how can it. try code not working
public int rowcount { { return (int)viewstate["rowcount"]; } set { viewstate["rowcount"] = value; } } protected void page_load(object sender, eventargs e) { if (!ispostback) { fetchdata(5, 0); } else { placeholder1.controls.clear(); createpagingcontrol(); } } private void fetchdata(int take,int pagesize) { var doc = xdocument.load(server.mappath("~/blogcontent.xml")); var result = doc.descendants("post").where(x => x.element("id") != null).take(take).skip(pagesize) .select(x => new { id = x.element("id").value, title = x.element("title").value, description = x.element("discription").value, dt = x.element("dt").value, mnt = x.element("mnt").value, yr = x.element("yr").value, postdate = x.element("postdate").value }).orderbydescending(x => x.id); pageddatasource page = new pageddatasource(); page.allowpaging = true; page.allowcustompaging = true; page.datasource = result; page.pagesize = 10; if (!ispostback) { rowcount = result.count(); } } private void createpagingcontrol() { (int = 0; < (rowcount / 10) + 1; i++) { linkbutton lnk = new linkbutton(); lnk.click += new eventhandler(lbl_click); lnk.id = "lnkpage" + (i + 1).tostring(); lnk.text = (i + 1).tostring(); placeholder1.controls.add(lnk); label spacer = new label(); spacer.text = " "; placeholder1.controls.add(spacer); } } void lbl_click(object sender, eventargs e) { linkbutton lnk = sender linkbutton; int currentpage = int.parse(lnk.text); int take = currentpage * 10; int skip = currentpage == 1 ? 0 : take - 10; fetchdata(take, skip); }
when using code previous , next buttons working data on repeater not changing
have @ :
void lbl_click(object sender, eventargs e) { linkbutton lnk = sender linkbutton; int currentpage = int.parse(lnk.text); int take = currentpage * 10; int skip = currentpage == 1 ? 0 : take - 10; fetchdata(take, skip); }
what saying display 10 times number of currentpage in rows. instance if in page 4 going display 40 rows, whereas in page 5 display 50 rows.
then dictate how many rows skip, in first page skip none, in page 4 skip 40 - 10 = 30 rows. should take predefined set of rows, ie 10 , skip variable.
for instance should have code as:
void lbl_click(object sender, eventargs e) { linkbutton lnk = sender linkbutton; int currentpage = int.parse(lnk.text); int take = 10; int skip = (currentpage - 1) * 10; fetchdata(take, skip); }
in page 1 skip 0 rows, in page 2 10 rows etc.
you take under consideration on having take number in user defined variable...
edit
you should check page_load
protected void page_load(object sender, eventargs e) { if (!ispostback) { fetchdata(5, 0); } else { placeholder1.controls.clear(); createpagingcontrol(); } }
in initial load of data take 5 first rows , skip 0. if change
fetchdata(10, 0);
you should ok.
giannis
Comments
Post a Comment