0

请看下面的代码:

Protected Sub GVHistoricNames_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GVHistoricNames.RowUpdating
            Try
                'Dim strUsercode As String = GVHistoricNames.Rows(e.RowIndex).Cells(2).Text
                Dim ddl As DropDownList = CType(GVHistoricNames.Rows(e.RowIndex).FindControl("ddlUsercode"), DropDownList)
                MsgBox(ddl.SelectedIndex)


            Catch ex As Exception
                 'I don't swallow exceptions
            Finally

            End Try
        End Sub

我正在尝试获取下拉列表的选定值。模板字段定义如下:

<asp:TemplateField HeaderText="Usercode">
                 <ItemTemplate>
                <asp:DropDownList ID="ddlUsercode" runat="server" SelectedValue ='<%# Bind("Usercode") %>' DataTextField="Usercode" DataValueField="Usercode">
                </asp:DropDownList> 
                </ItemTemplate>
            </asp:TemplateField>

MsgBox(ddl.SelectedIndex) 总是在 GVHistoricNames_RowUpdatinGVHistoricNames_RowUpdating 中打印一个空字符串。我在做什么?

4

1 回答 1

0

检查您是否没有在 rowUpdating 事件之前的页面生命周期中的某个位置绑定或填充下拉列表。确保您not isPostback酌情使用。检查那里的语法,因为我是 C# 人!

于 2012-11-26T22:48:02.300 回答