datagrid and radio buttons

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

I noticed somewhere on the net that a post mentioned that there was a bug in
the datagrid, radio buttons and a repeater. Something about the radio
buttons are not mutually exclusive. (will this be fixed soon)

I am trying to create a survey form where the 4 radio buttons are created
dynamically for each question in the database. Is there an example of this
somewhere. The radio buttons are based on a seperate table called survey
answers. What I am looking for is what does the html look like and how do I
write the code to handle the server side events.

Thank You All for participating
 
Customizing the datagrid to use radio buttons requires a couple lines of
code. I provide an example here as alternative to downloading and installing
a component.

In your datagrid itemdatabound event handler, this line of code adds a
radiobutton to each row.
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)

{

Label lbl = (Label)e.Item.FindControl("Dig");

if(lbl != null)

lbl.Text = "<input type=radio name='samegroup' value='" +
e.Item.Cells[1].Text + "'>";

}
The code assumes that you have created a datagrid with an item template
column contianing a field called "Dig". This part is entirely optional as
you can just add the lbl control to any column.

The reason why mutually exclusive radio buttons don't work from the
code-behind is that the datagrid implements the INamingContainer interface
which forces each implementor to generator unique names for the html content
rendered clientside. Therefor, the mutually exclusivity is lost with the
unique renaming. Using javascript like the code provided above ensures that
the radio button created clientside has a family groupname.
 
Back
Top