ASP.NETで開発されたアプリケーションを使用していますが、直面している問題はFormViewコントロールの使用です。FormViewコントロールには、ItemTemplate、InsertItemTemplate、およびEditItemTemplateがあります。
以下は、InsertItemTemplateのコードフラグメントです。
<asp:FormView ID="FormView1" runat="server" DefaultMode="ReadOnly">
<InsertItemTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:Label id="lblPS" runat="server" Text="Process Status"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlPS" runat="server"></asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label id="lblAP" runat="server" Text="Action Plan"></asp:Label>
</td>
<td>
<asp:TextBox id="txtAP" runat="server" Width="230px" TextMode="MultiLine" Rows="5"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
Page_Loadイベントでは、次のように、DropDownListへのデータソースバインディングを実行します。
FormView1.ChangeMode(FormViewMode.Insert);
DropDownList ddlPS = FormView1.FindControl("ddlPS") as DropDownList;
ddlPS.DataSource=GetProcessStatus();
ddlPS.DataBind();
ddlPS.Items.Insert(0, new System.Web.UI.WebControls.ListItem("- Please Select -", "- Please Select -"));
DropDownListと「-PleaseSelect-」へのデータバインディングは問題ありませんでした。
ここで問題が発生します。[送信]ボタンをクリックすると、ユーザーが選択したDropDownList値を取得したかったのですが、DropDownList.SelectedItem.Textは常に「-選択してください-」を返します。
InsertItemTemplateでユーザーが選択した値を取得する方法を教えてください。