网格视图选择单选按钮

时间:2013-08-19 07:33:29

标签: vb.net gridview

我有像这样的简单网格视图

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1">
        <Columns>
            <asp:TemplateField HeaderText="Status">
                <HeaderTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server">
                        <asp:ListItem>A</asp:ListItem>
                        <asp:ListItem>B</asp:ListItem>
                        <asp:ListItem>C</asp:ListItem>
                    </asp:DropDownList>
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:RadioButtonList ID="chkStatusGM" runat="server" AutoPostBack="false" RepeatDirection="Horizontal">
                        <asp:ListItem Value="5">Approve</asp:ListItem>
                        <asp:ListItem Value="0">Not Approved</asp:ListItem>
                    </asp:RadioButtonList>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="CATEGORY" HeaderText="CATEGORY"  />

        </Columns>
    </asp:GridView>

在网格视图中,有单选按钮和列类别具有固定值,如“A”,“B”,“C i 问题是我想根据从下拉列表中选择的值来选择所有无线电。例如如果我从下拉列表中选择“A”,那么应该选择值为4的gridview中具有ctegory“A”的无线电。

1 个答案:

答案 0 :(得分:0)

我自己的解决方案这里是代码

Protected Sub ddlupd(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ddlupd As DropDownList = CType(GridView2.HeaderRow.FindControl("ddcat"), DropDownList)
        For Each gv As GridViewRow In GridView2.Rows
            Dim rdo As RadioButtonList = CType(GridView2.Rows(gv.RowIndex).FindControl("rblist"), RadioButtonList)
            Dim cat As Label = CType(GridView2.Rows(gv.RowIndex).FindControl("lblcat"), Label)
            If cat.Text = ddlupd.SelectedItem.Text Then
                rdo.SelectedValue = "4"
            ElseIf ddlupd.SelectedItem.Text = "Clear Selection" Then
                rdo.ClearSelection()
            ElseIf ddlupd.SelectedItem.Text = "Select All" Then
                rdo.SelectedValue = "4"
            End If
        Next
    End Sub