HtmlInputRadioButton Inside a Datalist

G

Guest

I am having some problem regarding radiobutton inside a datalist. I want to
have a radiobutton on each row of my datalist. I want to check a particular
button, all the other would remain unchecked. Also I want to get the checked
value from my code behind.

I have tried with the following code. Each time I click the button to find
the value of the radio button, getting an error "Object reference is not set".

HTML
====
(In the ItemTemplate of a DataList "dtlTesting")

<ItemTemplate>
<INPUT id="RBList" style="WIDTH: 16px; HEIGHT: 20px" type="radio"
name="group"><%# DataBinder.Eval(Container.DataItem, "Name") %></INPUT>
</ItemTemplate>


CodeBehind( On Button click)
============================

private void Button1_Click(object sender, System.EventArgs e)
{
foreach(DataListItem oItem in dtlTesting.Items)
{
//Find the previous selected RadioButton
bool blnRadio =
((System.Web.UI.HtmlControls.HtmlInputRadioButton)oItem.FindControl("RBList")).Checked;
string
str=((System.Web.UI.HtmlControls.HtmlInputRadioButton)oItem.FindControl("RBList")).Value;

if (blnRadio)
{
TextBox1.Text=str;
}
}
}
 
G

Guest

By using runat="server", all the radio buttons inside the datalist acts as
individual buttons, i.e., we can select all of them at a time which I don't
want. I want to select only one button at a time.
 
C

Christopher Reed

You cannot access your HtmlInputRadioButton from the server without it.

You can use an ItemCommand event for the your DataList and then access the
specific row radio input button using the event arguments parameter from the
corresponding method.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top