Checkbox Checking in DatalistPosted By :pavani Posted Date :01/07/2009 Points :2 Category :ADO.Net
|
| Hi I have a Datalist where i have written code for page navigation using PagedDataSource class.I have checkbox column in datalist now my problem is when i check some box in the first page and navigate to second page and come back to first page am loosing my checkbox status that is checked in datalist I donot want to loose the status of my checkbox during page navigation.i have tried to viewstate concept by making enableviewstate as true for datalist and also for datalist but its not working As said by one of our frds Using ArrayList i stored checked items in a session.In ItemDataBound Event I assign back the checked item which is available in arraylist session variable .am getting an exception unable to cast System.String to System.ArrayList This is my code jst have alook ArrayList al = new ArrayList(); protected void Page_Load(object sender, EventArgs e) { foreach (DataListItem dll in DataList1.Items) {
CheckBox chk = (CheckBox)dll.FindControl("CheckBox2"); if (chk.Checked == true) { al.Add(chk); Session["checkedboxes"] = al.ToString(); //Response.Write("" + al.Count);
} } if (!Page.IsPostBack) { BindList();//binding datalist
} } //BinList method public void BindList() {
PagedDataSource pds = new PagedDataSource(); try {
DataSet ds = Class1.Getstudentdetails("11", "8"); pds.AllowPaging = true; pds.DataSource = ds.Tables["Student"].DefaultView; pds.PageSize = 3; pds.CurrentPageIndex = CurrentPage;
DataList1.DataSource = pds; al = (ArrayList)Session["checkedboxes"]; DataList1.DataBind();
} catch (Exception ex) { throw ex; } protected void lbtnPrev_Click(object sender, System.EventArgs e) { CurrentPage -= 1; al = (ArrayList)Session["checkedboxes"]; BindList(); } protected void lbtnNext_Click(object sender, System.EventArgs e) {
CurrentPage += 1; al = (ArrayList)Session["checkedboxes"]; BindList();
} protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { al = (ArrayList)Session["checkedboxes"]; BindList(); } Is my code wrong? Then i have one more problem in 1st page i checked three checkboxes, so my arralist constists 3 k in 2nd page i chekd 2 i will add my arralist is 5 i go back 2 1st page then how wil iknow in 5 items which r checked in ist page and soon Please help me out Thanks in advance
|
|
|
You must
Sign In To post reply |