Monday, April 30, 2012

how to make single radio button selection in gridview using javascript


[head id="Head1" runat="server">
[title>Grdview with Arraylist
[style type="text/css">
.Gridview
{
font-family:Verdana;
font-size:10pt;
font-weight:normal;
color:black;
width:300px;
}
[/style>
[script language="javascript" type="text/javascript">
function SelectSingleRadiobutton(rdbtnid) {
var rdBtn = document.getElementById(rdbtnid);
var rdBtnList = document.getElementsByTagName("input");
for (i = 0; i < rdBtnList.length; i++) {
if (rdBtnList[i].type == "radio" && rdBtnList[i].id != rdBtn.id)
{
rdBtnList[i].checked = false;
}
}
}
[/script>
[/head>
[body>
[form id="form1" runat="server">
[div>
[asp:GridView ID="gvdata" runat="server" CssClass="Gridview" AutoGenerateColumns="false" DataKeyNames="UserId" HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White">
[Columns>
[asp:TemplateField>
[ItemTemplate>
[asp:RadioButton id="rdbUser" runat="server" OnClick="javascript:SelectSingleRadiobutton(this.id)" />
[/ItemTemplate>
[/asp:TemplateField>
[asp:BoundField DataField="UserName" HeaderText="Name"/>
[asp:BoundField DataField ="FirstName" HeaderText="FirstName" />
[asp:BoundField DataField="LastName" HeaderText="LastName" />
[asp:BoundField DataField="Location" HeaderText="Location" />
[/Columns>
[/asp:GridView>
[/div>
[/form>
[/body>
[/html>

No comments: