Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How To Select Only One Radio Button in GridView Control in C#

How To Select Only One Radio Button in GridView Control in C#

Scheduled Pinned Locked Moved ASP.NET
csharphelpasp-netsysadminjson
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrgaddam
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • M mrgaddam

      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

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      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)

      M 1 Reply Last reply
      0
      • M Michael Sync

        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)

        M Offline
        M Offline
        Michael Sync
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups