0

これは私のドロップダウンリストのコードです........

<td valign="top" align="center">
   <asp:DropDownList ID="StudentNameDropDownList" runat="server" Width="150px" 
       DataSourceID="SqlDataSource2" DataTextField="StudentName" 
       DataValueField="StudentName" AutoPostBack="True">
   </asp:DropDownList>
   <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
       ConnectionString="<%$ ConnectionStrings:dbbilling2.0ConnectionString3 %>" 

       SelectCommand="SELECT [StudentID], [StudentName] FROM [tblStudentInfo] WHERE ([Class] = @Class)">
       <SelectParameters>
           <asp:ControlParameter ControlID="ClassDropDownList" Name="Class" 
               PropertyName="SelectedValue" Type="String" />
       </SelectParameters>
   </asp:SqlDataSource>
   <br />


コード ビハインド ファイルの Student ID フィールドにアクセスしたいのですが、どうすればこれを達成できますか?? [dropdownlist.selecteditemのように]どの構文を使用する必要がありますか??

4

2 に答える 2

0


まず、DropDownList ASP コンポーネントで、プロパティ DataValueField="StudentID" を設定する必要があります。次に、コード ビハインドで次のように記述して、選択した学生の ID を取得できます。 StudentNameDropDownList.SelectedValue

于 2013-04-09T07:28:30.277 に答える