请参阅以下代码:
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。我在做什么?
答案 0 :(得分:0)
检查您是否未在rowUpdating事件之前的页面生命周期中的某些位置绑定或填充下拉列表。确保根据需要使用not isPostback
。检查那里的语法,因为我是C#家伙!