单选按钮选择的值不起作用

时间:2013-08-27 05:13:48

标签: asp.net vb.net

我试图从下拉列表的选定值中选择单选按钮,如下所示

    Dim ddlupd As DropDownList = CType(grid.HeaderRow.FindControl("dropdown"), DropDownList)
        For Each gv As GridViewRow In grid.Rows
            Dim rdo As RadioButtonList = CType(grid.Rows(gv.RowIndex).FindControl("list"), RadioButtonList)
            Dim cat As Label = CType(grid.Rows(gv.RowIndex).FindControl("lblcat"), Label)
            If cat.Text = ddlupd.SelectedItem.Text Then
                rdo.SelectedValue = selflg.ToString()
            ElseIf ddlupd.SelectedItem.Text = "Clear Selection" Then
                rdo.ClearSelection()
            ElseIf ddlupd.SelectedItem.Text = "Select All" Then
                rdo.SelectedValue = selflg.ToString()
            End If
        Next

并且gridview中有模板字段,如此

<asp:TemplateField HeaderText="Status">
     <HeaderTemplate>
         <asp:DropDownList ID="dropdown" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlupdGM1" BackColor="#3399FF" ForeColor="White">
             <asp:ListItem>Select Category</asp:ListItem>
             <asp:ListItem>Clear Selection</asp:ListItem>
             <asp:ListItem Value="1">Cane Payment</asp:ListItem>
             <asp:ListItem Value="2">Income Tax</asp:ListItem>
             <asp:ListItem Value="3">Fund Transfer</asp:ListItem>
             <asp:ListItem Value="4">Others</asp:ListItem>
         </asp:DropDownList>
     </HeaderTemplate>
     <ItemTemplate>
         <asp:RadioButtonList ID="chkStatusGM" runat="server" AutoPostBack="false" RepeatDirection="Horizontal" OnSelectedIndexChanged="chkStatus_OnCheckedChangedGM">
             <asp:ListItem Value="5">Approve</asp:ListItem>
             <asp:ListItem Value="0">Not Approved</asp:ListItem>
         </asp:RadioButtonList>
     </ItemTemplate>
 </asp:TemplateField>

此外,我正在使用选定的单选按钮值对数据库运行更新命令。问题是,当从标题模板的下拉值中选择单选按钮时,由于无效选择radiobutton而没有更新运行,当我手动选择单选按钮更新工作正常。

更新 **

Protected Sub chkStatus_OnCheckedChangedGM(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cmd As OleDbCommand = New OleDbCommand()

        Dim chkStatusGM As RadioButtonList = CType(sender, RadioButtonList)
        Dim row As GridViewRow = CType(chkStatusGM.NamingContainer, GridViewRow)
        Dim bpvnum As String = row.Cells(4).Text

        cmd.CommandText = "update sml.FND_01_11@wbg set sta_flg=:sta_flg where bpv_num=:bpv_num and bpv_dte=:bpv_dte"
        cmd.CommandType = CommandType.Text
        cmd.Connection = con

        cmd.Parameters.Add(":sta_flg", OleDbType.BigInt).Value = chkStatusGM.SelectedValue
        cmd.Parameters.Add(":bpv_num", OleDbType.BigInt).Value = bpvnum
        cmd.Parameters.Add(":bpv_dte", OleDbType.Date).Value = TreeView2.SelectedValue
        Try
            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
        Catch ex As Exception
            Response.Write(ex.ToString())
        End Try
    End Sub

**

1 个答案:

答案 0 :(得分:0)

调用单选按钮列表的SelectedIndexChanged事件(或您正在使用的任何事件处理程序):

Dim ddlupd As DropDownList = CType(grid.HeaderRow.FindControl("dropdown"), DropDownList)
    For Each gv As GridViewRow In grid.Rows
        Dim rdo As RadioButtonList = CType(grid.Rows(gv.RowIndex).FindControl("list"), RadioButtonList)
        Dim cat As Label = CType(grid.Rows(gv.RowIndex).FindControl("lblcat"), Label)
        If cat.Text = ddlupd.SelectedItem.Text Then
            rdo.SelectedValue = selflg.ToString()
        ElseIf ddlupd.SelectedItem.Text = "Clear Selection" Then
            rdo.ClearSelection()
        ElseIf ddlupd.SelectedItem.Text = "Select All" Then
            rdo.SelectedValue = selflg.ToString()
        End If

        ' call the event handler similar to manually clicking an option
        chkStatus_OnCheckedChangedGM(rdo, new System.EventArgs())
    Next