.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Forum >> ADO.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Checkbox Checking in Datalist

Posted By: pavani     Posted Date: July 01, 2009    Points:2   Category :ADO.Net
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)

Session["checkedboxes"] = al.ToString();
//Response.Write("" + al.Count);

if (!Page.IsPostBack)
BindList();//binding datalist

//BinList method
public void BindList()

PagedDataSource pds = new PagedDataSource();

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"];

catch (Exception ex)
throw ex;
protected void lbtnPrev_Click(object sender, System.EventArgs e)
CurrentPage -= 1;
al = (ArrayList)Session["checkedboxes"];

protected void lbtnNext_Click(object sender, System.EventArgs e)

CurrentPage += 1;
al = (ArrayList)Session["checkedboxes"];

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
al = (ArrayList)Session["checkedboxes"];
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

Author: Amit Mehra             
Posted Date: July 01, 2009     Points: 5   

The problem is pagedDataDource It Bind the datalist again.


1 way) User your pagination means Get The total number of records and fetch only that number of data

for eg

If user has clicked Page 3 and your DataList Page size is 10 than fetch only 30 to 40 records. in this way you can avoid loading much data as a result the performance also will be good.

2 Way) Have one global variable say ArrayList and store all the checked item value into that and assign this arraylist to session variable.

and in the In ItemDataBound Event You can assign back the checked item which is available in arraylist session variable.

Hope this will help you.

Please "Mark As Answer " if this post help you.

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend