带单选按钮的Gridview [英] Gridview with radio button

查看:87
本文介绍了带单选按钮的Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,
我有一个带有记录数的网格视图.在网格视图中,我有两个列单选按钮字段.我的要求是我需要在每个列记录中选择一个单选按钮.

示例:

Radiobtn1 radiobtn2
1 1
2 2
3 3


我只需要在每个列中选择一个单选按钮.

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.

推荐答案

在第一列的第一个单选按钮单击事件中使用.

if(radiobutton1.checked == true)
{
radiobutton2.checked = false; //gridview中第二列的单选按钮
}
反之亦然.

在每个单选按钮的单击事件中使用它.
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.


朋友,

请在下面找到解决方案.

将以下javascript添加到您的aspx页面.

Hi Friend,

Please find the solution below.

Add the below javascript to your aspx page.

<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>



希望您在GridView的TemplateField中有两个RadioButton字段/列,如下所示.在两个RadioButton的"onclick"事件中调用javascript.



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.

<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!!



我按照这些步骤来解决此问题...

步骤:1)首先为网格视图中的每一列设置每个组

第2步)根据您对单选按钮的要求进行下一步拆分

例如:如果在网格视图的第一列中包含一个,tw0,三个单选按钮......,则在这些关联的单选按钮的属性中设置属性(group = g1)
....像这样对下一个列执行相同的步骤....为(group = g2)设置....像那样

现在:它将在每一列中仅选择一个单选按钮.............

享受这些.........
感谢®ards,
nareshrajuu
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


这篇关于带单选按钮的Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆