0

我试图从这样的下拉列表的选定值中选择单选按钮

    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>

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

更新 **

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

**

4

1 回答 1

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
于 2013-08-27T05:50:00.567 回答