0
請參閱下面的代碼:ASP.NET - 模板字段下拉列表
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。我在做什麼?