CheckBoxList Question - C#

L

Lakshmi

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
 
C

csharp

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.Value =="True")

CheckBoxList1.Items.Selected=true;

}

}

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



Regards,

wl (Sjtu)
 
L

Lakshmi

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top