Saving values in different pages in a gridview,asp.net -
i have grid contains more 30 values.grid view page size 10 .grid view contains check box when select 2 datas in first page , go next page , select 2 data , enter ok button save last select value.i want save datas selected in different pages
thanks advance
you can try piece of code: *
protected void page_load(object sender, eventargs e) { if(!ispostback) { bindgriddata(); } } //this method used bind gridview protected void bindgriddata() { sqlconnection con = new sqlconnection("data source=xxx;integrated security=true;initial catalog=mysampledb"); sqlcommand cmd = new sqlcommand("select * userinformation", con); sqldataadapter da = new sqldataadapter(cmd); dataset ds = new dataset(); da.fill(ds); gvdetails.datasource = ds; gvdetails.databind(); } protected void gvdetails_pageindexchanging(object sender, gridviewpageeventargs e) { savecheckedvalues(); gvdetails.pageindex = e.newpageindex; bindgriddata(); populatecheckedvalues(); } //this method used populate saved checkbox values private void populatecheckedvalues() { arraylist userdetails = (arraylist)session["checked_items"]; if (userdetails != null && userdetails.count > 0) { foreach (gridviewrow gvrow in gvdetails.rows) { int index = (int)gvdetails.datakeys[gvrow.rowindex].value; if (userdetails.contains(index)) { checkbox mycheckbox = (checkbox)gvrow.findcontrol("chkselect"); mycheckbox.checked = true; } } } } //this method used save checkedstate of values private void savecheckedvalues() { arraylist userdetails = new arraylist(); int index = -1; foreach (gridviewrow gvrow in gvdetails.rows) { index = (int)gvdetails.datakeys[gvrow.rowindex].value; bool result = ((checkbox)gvrow.findcontrol("chkselect")).checked; // check in session if (session["checked_items"] != null) userdetails = (arraylist)session["checked_items"]; if (result) { if (!userdetails.contains(index)) userdetails.add(index); } else userdetails.remove(index); } if (userdetails != null && userdetails.count > 0) session["checked_items"] = userdetails; }
*
Comments
Post a Comment