以下のコードを参照してください。
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 に出力します。私は何をしているのですか?