1

我正在使用以下代码在我的 aspx 页面中显示下拉列表,并且下拉列表中加载的数据是由SqlDatasource4

 <asp:DropDownList ID="DropDownListnew" runat="server" 
     CssClass="ddlb" Width="210px" Height="30px" DataSourceID="SqlDataSource4" 
     DataTextField="OrderPeriod" DataValueField="OrderPeriodID">
 </asp:DropDownList>

当我尝试C#通过以下代码访问文件中的下拉数据时:

string data = DropDownListnew.Text;

它打印所选值的编号,我想将所选值存储在数据字符串中。我该怎么做?

4

3 回答 3

3

您可以通过以下方式访问它;

string data = DropDownListnew.SelectedValue; // property not .Text property
于 2012-08-23T18:12:30.320 回答
1
string data = DropDownListnew.SelectedValue;
于 2012-08-23T18:10:07.037 回答
0

从 DropDownList 中获取选定值的另一个属性。

string data = DropDownListnew.SelectedItem.Value;
于 2012-08-24T17:41:26.860 回答