radiobutton and datagrid

J

Joe Abou Jaoude

hi,
I have a datagrid. i want the user to select a row, and only one row. so
i created a template column where i placed a radiobutton...
Unfortunately this is not working, because the name of the radiobutton
is changing according to the datagrid row, so when i select a
radiobutton this won't deselect another radio button...

any idea how to do something similar
thx
 
E

Elton Wang

Hi Joe,

I believe it's possible to achieve goal of deselecting
other radio button, when selecting one.

For any server controls in a datagrid, there are two
properties you can use, ID and ClientID. For one server
control of a column in different rows, their IDs will be
same and ClientIDs will be different. So you can try
following code

RadioButton selectedRdBtn = (RadioButton)sender;
RadioButton rdBtn;
string clientID = selectedRdBtn.ClientID;
bool selected = selectedRdBtn.Checked;
foreach (DataGridItem item in datagrid.Items)
{
rdBtn = (RadioButton)item.FindControl("rdBtnID");
if(!rdBtn.ClientID.Equals(clientID)
{
rdBtn.Checked = !selected ;
}
}


HTH

Elton Wang
(e-mail address removed)
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top