datagrid and radio buttons

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
 
A

Alvin Bruney

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top