请看下面的代码:
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 中打印一个空字符串。我在做什么?