How To Select Only One Radio Button in GridView Control in C#
-
Hi, This is from Chandrakanth. Now I am working on asp.net 2.0 My Problem is i have one Page called "Search".In that search page i have Text Box called "txtUserName". And i entered some letter in that Textbox. Based on that letter list of records are displaying with Radio Buttons in gridview. And i want to select only one record from the gridview by selecting RadioButton. at present i can able to select multiple records by clicking radio buttons. i do want to select only one record, Then Rest of the radio buttons record should be unselect in gridview. Can any one help me for this. Thnaks in advance here i am giveing Gridview code also <table id="tblEmpDtls" cellspacing="2" cellpadding="2" width="100%" border="1" runat="server"> <tr> <td class="TableHead" colspan="2"> Employee Details</td> </tr> <tr> <td class="TableRow" colspan="4"> <asp:GridView ID="gdvUserSearch" runat="server" AllowPaging="True" AllowSorting="True" PageIndex="15" AutoGenerateColumns="False" Width="100%" Height="77px"> <Columns> asp:TemplateField <ItemTemplate> <asp:RadioButton ID="rdSelect" runat="server" Text="Select" GroupName="rdBox" OnCheckedChanged="rbdefault_CheckedChanged" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="User Id" DataField="UserId" /> <asp:BoundField HeaderText="User Name" DataField="UserName" /> <asp:BoundField HeaderText="Email Id" DataField="Email" /> <asp:BoundField HeaderText="Mobile No" DataField="Mobile_No" /> </Columns> </asp:GridView> </td> </tr> </table> Thanks and Regards Chandrakanth
Chandrakanth
-
Hi, This is from Chandrakanth. Now I am working on asp.net 2.0 My Problem is i have one Page called "Search".In that search page i have Text Box called "txtUserName". And i entered some letter in that Textbox. Based on that letter list of records are displaying with Radio Buttons in gridview. And i want to select only one record from the gridview by selecting RadioButton. at present i can able to select multiple records by clicking radio buttons. i do want to select only one record, Then Rest of the radio buttons record should be unselect in gridview. Can any one help me for this. Thnaks in advance here i am giveing Gridview code also <table id="tblEmpDtls" cellspacing="2" cellpadding="2" width="100%" border="1" runat="server"> <tr> <td class="TableHead" colspan="2"> Employee Details</td> </tr> <tr> <td class="TableRow" colspan="4"> <asp:GridView ID="gdvUserSearch" runat="server" AllowPaging="True" AllowSorting="True" PageIndex="15" AutoGenerateColumns="False" Width="100%" Height="77px"> <Columns> asp:TemplateField <ItemTemplate> <asp:RadioButton ID="rdSelect" runat="server" Text="Select" GroupName="rdBox" OnCheckedChanged="rbdefault_CheckedChanged" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="User Id" DataField="UserId" /> <asp:BoundField HeaderText="User Name" DataField="UserName" /> <asp:BoundField HeaderText="Email Id" DataField="Email" /> <asp:BoundField HeaderText="Mobile No" DataField="Mobile_No" /> </Columns> </asp:GridView> </td> </tr> </table> Thanks and Regards Chandrakanth
Chandrakanth
I think this issue[^] is valid in .NET 2.0. So, you should use the Javascript to handle that thing. see Radio Buttons in a Repeater Control[^] or you may use this radiobutton.[^] I have tried to use the Javascript from the link that I mentioned above.
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
-
I think this issue[^] is valid in .NET 2.0. So, you should use the Javascript to handle that thing. see Radio Buttons in a Repeater Control[^] or you may use this radiobutton.[^] I have tried to use the Javascript from the link that I mentioned above.
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
HTML view ========= ]]> Untitled Page function SetUniqueRadioButton(nameregex, current) { 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 (re.test(elm.name)) { elm.checked = false; } } } current.checked = true; }
ReadOnly="True" SortExpression="CustomerID" /> SelectCommand="SELECT [CustomerID], [CustomerName] FROM [Customers]">
Code-behinded ============== using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { string script = "SetUniqueRadioButton('" + GridView1.Clien