Reputation: 5637
I need to built a list of radio buttons, based on data I return from my DB. Each button needs to have a value associated with it that I can get out based on the selected button.
Ideally I would just use the RadioButtonList
control, however, I need to have a very custom layout which a RadioButtonList
doesn't appear to be able to handle.
An alternative would be to create individual RadioButton
s and wrap them in a Panel to group them. However, there doesn't appear to be a Value property on a RadioButton
?
Is there an alternative way to set a value to a RadioButton
control? Alternatively, a way to completely customise the RadioButtonList
output.
At the moment, I'm thinking I might have to resort to using HTML radio buttons with runat="server"
, must be a better way...?
Upvotes: 10
Views: 14180
Reputation: 465
For a quick and dirty set of STATIC radio buttons.
I used the Tag field in the Properties window to manually define a value.
If you are using a DB you should probably bind your data to it. You never know when you'll change a key or name.
Upvotes: 1
Reputation: 478
You can always try using attributes to save the associated value. eg)
radioButton.Attributes.Add("Key", "Value");
Set the Group property to be the same for all the radio buttons and you should be good to go. Just remember, ASP .Net has a slight problem if these individual radio buttons are in different rows of a repeater, gridview or some such grid-style.
Upvotes: 3
Reputation: 16393
You could create your own radio button class which extends the standard one and adds a value property:
public class ValueCheckBox : System.Web.UI.WebControls.RadioButton
{
public string Value { get; set; }
}
Upvotes: 4
Reputation: 125610
RadioButton control doesn't have Value property, that's right. You have to use Checked
instead.
Upvotes: -1