473,394 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

CheckBoxList Question - C#

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
2 12308
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bryce Budd | last post by:
Hello All, I've been a taker of information from newsgroups for a long time and thought I'd finally make a contribution back to the community whose supported me when I've needed it. After all...
4
by: dm_dal | last post by:
Is there a know issue surrounding the CheckBoxList control and it's viewstate? When my control is created, it's ListItems are checked as needed, but on a postback, they loose their Selected...
4
by: Shaul Feldman | last post by:
Hello, I have something really awkward at work - fighting with CheckBoxList... How can I define CSS for ListItem in CheckBoxList programmatically. I add CheckBoxList's Items on the fly, something...
5
by: Eirik Eldorsen | last post by:
I'm trying to code a reapter that for each listelement show a checkboxlist. I'm almost there. The only thing I can't figure out is how to set the ID of the checkboxlists. This is my code:...
3
by: I am Sam | last post by:
I keep getting the following error message when I try to iterate through a CheckBoxList control: Object reference not set to an instance of an object. Description: An unhandled exception...
5
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able...
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
2
by: Patrick.O.Ige | last post by:
I have some boolean value(1 or 0 ) in a table and i want a databinded CheckBoxList to present the selected values on the page.. With CheckBox i know i can se the Checked property like so :-...
0
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView...
0
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.