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