By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,668 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,668 IT Pros & Developers. It's quick & easy.

CheckBoxList Question - C#

P: n/a
Hello,

I am using Visual Studio .Net and am new to web development. I have added a
CheckBoxlist to my web form (.aspx) and am populating the checkboxlist from
a table in the database and am selecting 4 options (as default) in the
Page_load event of the form. Now when the user selects more options or
deselects some options I save it and draw some graphs on another page. The
problem is the user selected options are not saved and I see only the
default options that the page had initially. The auto postback when set to
true just resets my page with the 4 default options. How can I trap the
user selected options? Some example code would be useful.

Thanks heaps,
Lakshmi
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Lakshmi,

Maybe, you can add this code in your Page_Load function.

I wrote them using c#:

if(!this.IsPostBack)

{

initial();

}

private void initial()// you can replace the following code to your own code

{

string query="select * from box";

conn=new SqlConnection(strConn);

conn.Open();

System.Data.SqlClient.SqlDataAdapter ad=new SqlDataAdapter(query,conn);

ds=new DataSet ();

ad.Fill(ds);

System.Data.DataView dw=new DataView(ds.Tables[0]);

CheckBoxList1.DataSource =dw;

CheckBoxList1.DataBind();

conn.Close();

for (int i=0; i<CheckBoxList1.Items.Count; i++)

{

if(CheckBoxList1.Items[i].Value =="True")

CheckBoxList1.Items[i].Selected=true;

}

}

Then, where you click button or set autopostback option, the CheckBoxList
will not be initialized again.

Regards,

wl (Sjtu)

"Lakshmi" <la*****@ayrdata.com> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
Hello,

I am using Visual Studio .Net and am new to web development. I have added a CheckBoxlist to my web form (.aspx) and am populating the checkboxlist from a table in the database and am selecting 4 options (as default) in the
Page_load event of the form. Now when the user selects more options or
deselects some options I save it and draw some graphs on another page. The problem is the user selected options are not saved and I see only the
default options that the page had initially. The auto postback when set to true just resets my page with the 4 default options. How can I trap the
user selected options? Some example code would be useful.

Thanks heaps,
Lakshmi

Nov 13 '05 #2

P: n/a
Thanks a lot. It works now, but there is another problem. When I hit the
back button on the browser it keeps going back to the previous selection of
the same page. Is there a way I can get it to go back the previous page
rather than the same page with different settings?
Lakshmi
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.