我正在尝试在下拉列表中选择值的文字,但它没有显示值但是' - 选择 - '
代码:
if (Convert.ToBoolean(ViewState["Response"])) {
String InvoiceNo= Convert.ToString(ViewState["InvoiceNo"]);
String ConductorName = Convert.ToString(DropDownListConductors.SelectedItem.Text);
Response.Redirect("~/ManageTransport/ConductorSlip.aspx?InvoiceNo=" + InvoiceNo+"&ConductorName="+ConductorName);
}
}
DDL:
DropDownListConductors.DataSource = ManageTransport.ManageConductorDevices.GetConductors();
DropDownListConductors.DataTextField = "Name";
DropDownListConductors.DataValueField = "ConductorID";
DropDownListConductors.DataBind();
DropDownListConductors.Items.Insert(0, new ListItem("-Select-", "0"));
ConductorSlip.aspx
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
ConductorName = Request.QueryString["ConductorName"].ToString();
}
}
的.aspx
<tr>
<td>Conductor Name</td>
<td><%=ConductorName %></td>
</tr>
答案 0 :(得分:0)
更新您的代码:
String ConductorName = Convert.ToString(DropDownListConductors.SelectedItem.Text);
到
用于选择值
String ConductorName = DropDownListConductors.SelectedValue;
用于选择文字
String ConductorName = DropDownListConductors.SelectedItem.Text;
了解更多信息click here
答案 1 :(得分:0)
我认为您不需要使用Conver.ToString(),因为Text属性已经是String。
请参阅以下代码: -
string ConductorName = DropDownListConductors.SelectedItem.Text;