Click here to Skip to main content
15,906,296 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir,
I have a grid view with number of records. Inside the grid view i have two column radio button fields. my requirement is i need to select any one of the radio button in each column record.

Example:

Radiobtn1 radiobtn2
1 1
2 2
3 3


i need to select only one radiobutton each column.
Posted

use on first radiobutton click event of first column.

if(radiobutton1.checked==true)
{
radiobutton2.checked=false; //radio button of second column in gridview
}
and vice versa.

use it on click event of every radio button.
 
Share this answer
 
Comments
stanly jeba singh 29-Mar-12 3:01am    
it was rough
Hi Friend,

Please find the solution below.

Add the below javascript to your aspx page.

XML
<script language="javascript" type="text/javascript">
        function SelectSingleRadiobutton(rdbtnid, id) {
            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) {
                    var radname = rdBtnList[i].getAttribute('name');
                    var radid = radname.substring(radname.length - 4, radname.length);
                    if (radid == id)
                        rdBtnList[i].checked = false;
                }
            }
        }
</script>


Hope you have two RadioButton fields / columns placed in the TemplateField of your GridView as below. Invoke the javascript in the "onclick" event of both RadioButton.

XML
<asp:TemplateField HeaderText="Radio 1">
    <ItemTemplate>
        <asp:RadioButton type="radio" ID="rad1" runat="server" onclick="SelectSingleRadiobutton(this.id,'rad1');"  />
    </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Radio 2">
    <ItemTemplate>
        <asp:RadioButton type="radio"  ID="rad2" runat="server" onclick="SelectSingleRadiobutton(this.id,'rad2');" />
    </ItemTemplate>
</asp:TemplateField>



Hope this helps you!!
 
Share this answer
 
v2
hi
i followed these step to achieve this problem...

step: 1) first set each group for each column in the grid view

step 2) next split as per u r requirements's for radio button

for example: if we have in first column of grid view consis of one,tw0,three radio buttons ......in properties of these associated radiobuttons set property (group=g1)
....like this do the same steps for next column ....set for (group=g2).......like that

now: it will take in each column selects only one radio button .............

enjoy these.........
thanks ®ards,
nareshrajuu
 
Share this answer
 
Comments
Member 8412080 26-Apr-12 1:37am    
How to select one of radio button in a column?From upper code,the output i get is can select 1 radio button only...
Member 8412080 26-Apr-12 1:47am    
I would like to select the radio button in every row.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900