CheckBoxList Data Binding

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Hi,

I have a webform which has DropDownList, RadioButtonList
and CheckBoxList. All values are in webform, but not
select from DB table as they do not need to be used as
search requirements.

For DropDownList and RadioButtonList, there is only one
item is selected and store in DB table.

I use

this.DropDownListItem.SelectedItem.Value = ds
["DropDownListItem"].ToString();
and
this.RadioButtonListItem.SelectedItem.Value = ds
["RadioButtonListItem"].ToString();

When the user edit the values of DropDownList and
RadioButtonList, the web form will display the selected
options.

However, how can I deal with a CheckBoxList? I can use a
foreach loop to get the selected values.

How can the selected values of CheckBoxList be displayed
in the web form when the user wants to edit it next time?
Do I need a delimitor to separate the checkboxlist values
before store them in DB?

Any better idea?

Thanks
 
Tom said:
Hi,

I have a webform which has DropDownList, RadioButtonList
and CheckBoxList. All values are in webform, but not
select from DB table as they do not need to be used as
search requirements.

For DropDownList and RadioButtonList, there is only one
item is selected and store in DB table.

I use

this.DropDownListItem.SelectedItem.Value = ds
["DropDownListItem"].ToString();
and
this.RadioButtonListItem.SelectedItem.Value = ds
["RadioButtonListItem"].ToString();

When the user edit the values of DropDownList and
RadioButtonList, the web form will display the selected
options.

However, how can I deal with a CheckBoxList? I can use a
foreach loop to get the selected values.

How can the selected values of CheckBoxList be displayed
in the web form when the user wants to edit it next time?
Do I need a delimitor to separate the checkboxlist values
before store them in DB?

Any better idea?

Thanks

Tom,

You can iterate the items in the checkboxlist using a couple of ways,
one way i would use would be like:

for(int i=0;i<lstJonel.Items.Count;i++) {
if (lstJonel.Items.Selected==true)
Business.LogManager.LogEvent(lstJonel.Items.Value);
}//for


hope the code give you a hint on where to go from here.

regards,
Jonel
 
Back
Top