Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
been searching but i still couldnt find any samples for adding a radiobutton control in a table control, anyone?

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Posted
thanks bri189a, how do i get its properties after posting back? is it the same as the dragged controls?

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Posted (edited)

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.

Edited by lamy

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Posted
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?
Anybody looking for a graduate programmer (Midlands, England)?
Posted (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' date=' could it be that this is what your looking for, or have I got the wrong end of the stick?[/quote']

 

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.

Edited by lamy

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Posted

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.

Posted (edited)

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 ;)

 

There is no value property' date=' only checked.[/quote']

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.

Edited by lamy

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Posted (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

 

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)

 

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

<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.

Edited by lamy

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...