使用VB在gridview中逐行访问单选按钮列表中的selectedValue [英] Access radiobuttonlist selectedvalue in gridview row by row using VB

查看:73
本文介绍了使用VB在gridview中逐行访问单选按钮列表中的selectedValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在其中一列中有一个带有单选按钮列表的gridview.单选按钮列表由用户需要选择的是/否选项组成.我想逐行访问gridview以获取单选按钮列表的selectedvalue,但是我不知道如何一个一个地访问它.

任何人都可以帮助我吗?

这是我的gridview代码:

Hi,

I have a gridview with a radiobuttonlist in one of the columns. The radiobutton list consist of Yes/No options where the users need to choose. I want to access the gridview row by row to get the selectedvalue of the radiobutton list but I do not have any idea how to access it one by one.

Anyone please help me?

This is my gridview code:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 

        DataKeyNames="QuestionNo" DataSourceID="SqlDataSource1">
        <Columns>
            <asp:BoundField DataField="QuestionNo" HeaderText="QuestionNo" ReadOnly="True" 

                SortExpression="QuestionNo" />
            <asp:BoundField DataField="Question" HeaderText="Question" 

                SortExpression="Question" />
            <asp:TemplateField HeaderText="Answer">
                <ItemTemplate>
                    <asp:RadioButtonList ID="rb1" runat="server">
                        <asp:ListItem Value="1">Yes</asp:ListItem>
                        <asp:ListItem Value="0">No</asp:ListItem>
                    </asp:RadioButtonList>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

推荐答案

我同意上面的回答,只是做了一点改进.
按照这种方式;
I agree with answer above, just a little enhancement.
Follow this way;
foreach (GridViewRow row in GridView1.Rows)
{
    RadioButtonList rbSelect = (RadioButtonList)row.FindControl("rbl");
    ////TO DO: Write the required code.

}



我本可以在VB.Net中提供此代码,但是我们将使其变得更加容易,只需点击下面的此链接即可;
将C#转换为VB.Net [



I could have provided this code in VB.Net, but we''ll make it more easy, just follow this link below;
C# to VB.Net[^]


以下是方法

Following is the way

GridviewRow gvr=GridView1.Rows[GridView1.SelectedIndex];
RadioButtonList rbl=gvr.findcontrol("rb1") as RadioButtonList ;
string result =  rbl.SelectedValue;


foreach (GridViewRow gvr in GridView1.Rows)
           {

     RadioButtonList rb = gvr.FindControl("rb1") as RadioButtonList

string ans=rb.selectedvalue;
}


这篇关于使用VB在gridview中逐行访问单选按钮列表中的selectedValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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