D
Dave Hall
I have a DataSet with two columns that I want to bind to a CheckBoxList. One column of the DataSet is a datetime field called HourOfDay. I want just the time portion of this column to become the text. The second column in the DataSet is a Bit column called "Checked". I want it to control if the checkbox for a particular hour of the day is checked or not. The following code displays the time column properly, but none of the checkboxes are checked. How should I bind the checkboxes to the "Checked" column in the DataSet?
Thanks,
Dave
Here's the code I'm using for binding the DataSet to the CheckBoxList:
CheckBoxList1.DataSource = dataSet;
CheckBoxList1.DataTextField = "HourOfDay";
CheckBoxList1.DataTextFormatString = "{0:h:mm tt}";
CheckBoxList1.DataValueField = "Checked";
CheckBoxList1.DataBind();
Here's the resulting display:
8:00 AM
9:00 AM
10:00 AM
11:00 AM
12:00 PM
1:00 PM
2:00 PM
3:00 PM
4:00 PM
5:00 PM
Here's the dataset contents:
Checked HourOfDay
------- -------------------
1 2004-08-09 08:00:00
0 2004-08-09 09:00:00
1 2004-08-09 10:00:00
1 2004-08-09 11:00:00
0 2004-08-09 12:00:00
1 2004-08-09 13:00:00
1 2004-08-09 14:00:00
0 2004-08-09 15:00:00
1 2004-08-09 16:00:00
1 2004-08-09 17:00:00
Thanks,
Dave
Here's the code I'm using for binding the DataSet to the CheckBoxList:
CheckBoxList1.DataSource = dataSet;
CheckBoxList1.DataTextField = "HourOfDay";
CheckBoxList1.DataTextFormatString = "{0:h:mm tt}";
CheckBoxList1.DataValueField = "Checked";
CheckBoxList1.DataBind();
Here's the resulting display:
8:00 AM
9:00 AM
10:00 AM
11:00 AM
12:00 PM
1:00 PM
2:00 PM
3:00 PM
4:00 PM
5:00 PM
Here's the dataset contents:
Checked HourOfDay
------- -------------------
1 2004-08-09 08:00:00
0 2004-08-09 09:00:00
1 2004-08-09 10:00:00
1 2004-08-09 11:00:00
0 2004-08-09 12:00:00
1 2004-08-09 13:00:00
1 2004-08-09 14:00:00
0 2004-08-09 15:00:00
1 2004-08-09 16:00:00
1 2004-08-09 17:00:00