How to assign Text and "hidden" record ID to a checkbox control?
am 08.04.2008 17:44:31 von dan
I'd like to list multiple records from a database as checkboxes. I'd use
record's "Name" column for checkbox Text. Ideally I'd like to assign a
'hidden' record's ID to checkbox so I don't need to go back to the database
to query for the ID when checkbox is clicked on.
This is similar to what can be done with DropDownList (i.e. text and value).
Is there a way to do that with checkboxes?
Thanks,
Dan
Re: How to assign Text and "hidden" record ID to a checkbox control?
am 08.04.2008 18:00:32 von dlongnecker
If you have a list of controls, you can use the CheckBoxList control and
assign it just like a DropDownList:
CheckBoxList cbList = new CheckBoxList();
cbList.DataSource = GetProducts();
cbList.DataTextField = "ProductName";
cbList.DataValueField = "ProductID";
cbList.DataBind();
HTH.
-dl
--
David R. Longnecker
http://blog.tiredstudent.com
> I'd like to list multiple records from a database as checkboxes. I'd
> use
> record's "Name" column for checkbox Text. Ideally I'd like to assign
> a
> 'hidden' record's ID to checkbox so I don't need to go back to the
> database
> to query for the ID when checkbox is clicked on.
> This is similar to what can be done with DropDownList (i.e. text and
> value).
> Is there a way to do that with checkboxes?
> Thanks,
> Dan