In .aspx Page:
Add this below javascript in aspx page :
<script type="text/javascript">
function SetSingleRadioButton(nameregex, current) {
var pp=eval("nameregex");
alert(pp);
re = new RegExp(nameregex);
for (i = 0; i < document.forms[0].elements.length; i++)
{
elm = document.forms[0].elements[i];
if (elm.type == 'radio') {
if (elm != current)
{
elm.checked = false;
}
}
}
current.checked = true;
}
</script>
Then in aspx Page use datalist and radio button as shown:
<asp:DataList id="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">
<ItemTemplate>
<table style="margin-top:-10px;" border="0">
<tr>
<td>
<asp:RadioButton ID="rdb" runat="server" Checked="false" GroupName="rdGroupOfMine" onKeyPress="return suppress(event);" />
<asp:Label ID="lbl_Rdb" runat="server" Text='<%# Eval("ADDR_CODE") %>' Visible="false"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
In code behind page:
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
return;
RadioButton rdb = (RadioButton)e.Item.FindControl("rdb");
Label lbl = (Label)e.Item.FindControl("lbl_Rdb");
string script = "SetSingleRadioButton('" + lbl.Text + "',this)";
rdb.Attributes.Add("onclick", script);
}
Add this below javascript in aspx page :
<script type="text/javascript">
function SetSingleRadioButton(nameregex, current) {
var pp=eval("nameregex");
alert(pp);
re = new RegExp(nameregex);
for (i = 0; i < document.forms[0].elements.length; i++)
{
elm = document.forms[0].elements[i];
if (elm.type == 'radio') {
if (elm != current)
{
elm.checked = false;
}
}
}
current.checked = true;
}
</script>
Then in aspx Page use datalist and radio button as shown:
<asp:DataList id="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">
<ItemTemplate>
<table style="margin-top:-10px;" border="0">
<tr>
<td>
<asp:RadioButton ID="rdb" runat="server" Checked="false" GroupName="rdGroupOfMine" onKeyPress="return suppress(event);" />
<asp:Label ID="lbl_Rdb" runat="server" Text='<%# Eval("ADDR_CODE") %>' Visible="false"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
In code behind page:
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
return;
RadioButton rdb = (RadioButton)e.Item.FindControl("rdb");
Label lbl = (Label)e.Item.FindControl("lbl_Rdb");
string script = "SetSingleRadioButton('" + lbl.Text + "',this)";
rdb.Attributes.Add("onclick", script);
}
2 comments:
Thanks a looooooootttt.. its working fine..
Thanks @Murli
Post a Comment