How to group RadioButtons in Datalist/Gridview control

Posted: October 29, 2013 in, c#
Tags: , ,

To select one radio button at a time in datalist, please follow below steps

Step 1: Write this Past below JavaScript in the aspx source code 

<script type=”text/javascript” language=”javascript”>
function CheckOnes(spanChk)
var oItem = spanChk.children;
var theBox= (spanChk.type==”radio”) ? spanChk : spanChk.children.item[0];


if(elm[i].type==”radio” && elm[i].id!

Step 2: Now data list as

<asp:DataList ID=”dlExample” runat=”server” RepeatDirection=”Vertical” RepeatColumns=”4″ OnItemDataBound=”dlExample_ItemDataBound” >
<table> <tr> <td> <asp:RadioButton ID=”rdb” runat=”server” /> </td> </tr> </table>

Step 3: In code behind

protected void dlExample_ItemDataBound(object sender, DataListItemEventArgs e)
RadioButton rdb;
rdb = (RadioButton)e.Item.FindControl(“rdb”);
if(rdb != null)
rdb.Attributes.Add(“onclick”, “CheckOnes(this);”);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s