add radiobutton control in a table control

thanks again bri189a, that made my codes shorter than using a literalcontrol, but i cant figure out how to set the value of the radiobutton, cant find any .Value in my properties.

what i did is changed the value of ID instead, and set my GroupName so i could still check it as one (i think), but i still havent tried accessing the value after the postback, obviously i couldnt use the GroupName yet, so ill probably use a .FindControl, but would it work with GroupName, since my ID is no longer the same as GroupName.
 
Last edited:
I don't know anything about asp development but I just thought I'd asked what exactly a .Value property would entail for a Checkbox? Certainly in windows form development a Checkbox has a .Checked value, could it be that this is what your looking for, or have I got the wrong end of the stick?
 
Cags said:
I don't know anything about asp development but I just thought I'd asked what exactly a .Value property would entail for a Checkbox? Certainly in windows form development a Checkbox has a .Checked value, could it be that this is what your looking for, or have I got the wrong end of the stick?

Cags, in HTML radio/checkbox button has both VALUE and CHECKED property, FYI, CHECKED property refers to the state of the radio/checkbox button, while VALUE property refers to the value if the buttons CHECKED property is set to TRUE, in short if its selected then it'll have a value, and none if it isnt.
 
Last edited:
There is no value property, only checked. If you need to know the 'value' of a radio button because you're show a 'group' of options you typically use a RadioButtonList control. Each radio button is an item in the Items collection property:

Me.RadioButtonList1.Items.Add("Choice 1")
Me.RadioButtonList1.Items.Add("Choice 2")

This will render the following:

<table id="RadioButtonList1" border="0" style="width:248px;Z-INDEX: 102; LEFT: 408px; POSITION: absolute; TOP: 288px">
<tr>
<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="Choice 1" /><label for="RadioButtonList1_0">Choice 1</label></td>
</tr><tr>
<td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="Choice 2" /><label for="RadioButtonList1_1">Choice 2</label></td>
</tr>
</table>

This is a little more html than you're use to see for a radio button group, but as you can see you still have your 'value' and the name groups them together.

To determine the change you could either wire up an event to the RadioButtonList_SelectedIndexChanged event in the code behind or query the selected value by:

Me.RadioButtonList1.SelectedValue

in the code behind. There are also other ways of doing this to, but this is probably closest to what you are looking for. If you want to pre-select a radio button before the page has loaded you can do:

Me.RadioButtonList1.SelectedValue = "Choice 1"

Again there are other ways to do this - I myself rarely use SelectedValue - but that's because my selections are generally data bound so I don't know what the values are.

Hope this helps.
 
thanks again bri189a, i guess ill be re-doing some stuffs, anyway its doing fine with the workaround since it all falls to a simple radio form object when it comes to html, but just to be safe i am re-coding ;)

bri189a said:
There is no value property, only checked.
i did underlined the word HTML, i wasnt referring to controls when i said it has those properties, anyway those controls are just some pre-rendered html objects limited to whatever.
 
Last edited:
:D oops, i think that made it a little complicated for me

the radiobuttons resides in different table rows in my table control, as a workaround i used ID since itll have the same value as my Value

Visual Basic:
row = New TableRow
col = New TableCell
radio = New RadioButton

with radio
   .GroupName = "myRadioButton"
   .ID = "myValue"
   .Text = "myDescription"
end with

col.Controls.Add(radio)
row.Cells.Add(col)
myTable.Rows.Add(row)

since im changing it to RadioButtonList how do i insert it to my table control (displaying it in different table rows per item)

Visual Basic:
radio = New RadioButtonList
With radio
   .ID = "myRadioButton"
   .Items.Add(New ListItem("myDescription", "myValue"))
End With

the HTML that i intend to render is something like this
Code:
<table>
<tr>
   <td colspan="2">
   Something goes here like category or brief description
   </td>
</tr>
<tr>
   <td>
    
   </td>
   <td>
   <input type="radio" name="myRadioButton" value="myValue"> myDescription
   </td>
</tr>
..
</table>

there are some rows that has textbox in it depending on the value of the radio or even other controls, thats why i needed it on a separate table row.
 
Last edited:
Back
Top