I want to create a checkboxlist, where the text field is the person's name, and where the value (checked or not) comes from the field (is_an_entrepreneur), but I also need the ID of the person that was selected.
I can create a checkboxlist that binds to a sqldatasource, and shows the person's name, and is checked based on "is_an_entreprenur". But if the user then clicks an UPDATE button, and I iterate though the checkboxes, I don't know which ID the checkbox corresponds
to.
Suppose I have a checkboxllist where the value of a checkbox is 82, the text of the checkbox is "Average age of death in Botswana" and the selected property is TRUE.
I want to populate this checkboxlist from a sqldatasource.
I can bind the 'text' and the 'value' of the checkbox, but I can't bind the "selected" property.
gidmeister
Member
112 Points
135 Posts
Using a checkboxlist with a datasource - can it use 3 pieces of information?
Nov 26, 2012 10:03 PM|LINK
Suppose I have a sql server table such as:
ID, person_name, is_an_entrepreneur
I want to create a checkboxlist, where the text field is the person's name, and where the value (checked or not) comes from the field (is_an_entrepreneur), but I also need the ID of the person that was selected.
I can create a checkboxlist that binds to a sqldatasource, and shows the person's name, and is checked based on "is_an_entreprenur". But if the user then clicks an UPDATE button, and I iterate though the checkboxes, I don't know which ID the checkbox corresponds to.
Is there a solution to this?
sarathi125
Star
13599 Points
2691 Posts
Re: Using a checkboxlist with a datasource - can it use 3 pieces of information?
Nov 27, 2012 05:03 AM|LINK
Hi,
Try something like the following,
public class SiteKey
{
public int Id { get; set; }
public int CustomerId { get; set; }
public override string ToString()
{
return Id.ToString() + "|" + CustomerId.ToString();
}
}
and in the method that retrieves the key:
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
gidmeister
Member
112 Points
135 Posts
Re: Using a checkboxlist with a datasource - can it use 3 pieces of information?
Nov 27, 2012 12:23 PM|LINK
I didn't ask my question correctly.
Suppose I have a checkboxllist where the value of a checkbox is 82, the text of the checkbox is "Average age of death in Botswana" and the selected property is TRUE.
I want to populate this checkboxlist from a sqldatasource.
I can bind the 'text' and the 'value' of the checkbox, but I can't bind the "selected" property.
What am I missing?
Thanks,
-- Gid
gidmeister
Member
112 Points
135 Posts
Re: Using a checkboxlist with a datasource - can it use 3 pieces of information?
Nov 27, 2012 05:43 PM|LINK
I found out it cannot be done at all. I'm using a gridview now, which can be made to look like a row of checkboxes without update buttons on each row.