我在p1.aspx上有这个下拉列表:
<select id="ListBoxViewType" style="width:160px;font-family:Tahoma;visibility:hidden;">
<option value="Amendment">Amendment</option>
<option value="Agreement">Full Terms Amendment</option>
<option value="Both">Both</option>
</select>
我需要在p2.asmx.cs上获得它的价值:
if ( <insert something like this: ListBoxViewType.Value=="Amendment">)
{
fileName = chReadData.ContractNumber +"_Amendment" +"-" + chReadData.DisplaySupplementNumber;
description = "Amendment for " + chReadData.ContractNumber + "-" + chReadData.DisplaySupplementNumber + " (\"" + chReadData.ContractDescription + "\")";
}
else
{
fileName = chReadData.ContractNumber +"_Full_Amendment" +"-" + chReadData.DisplaySupplementNumber;
description = "Amendment for " + chReadData.ContractNumber + "-" + chReadData.DisplaySupplementNumber + " (\"" + chReadData.ContractDescription + "\")";
}
答案 0 :(得分:1)
只需将runat="server"
添加到您的选择元素:
<select id="ListBoxViewType" runat="server" style="width:160px;font-family:Tahoma;visibility:hidden;">
<option value="Amendment">Amendment</option>
<option value="Agreement">Full Terms Amendment</option>
<option value="Both">Both</option>
</select>
要获得所选值,您可以使用:
this.ListBoxViewType.SelectedIndex
此外,您应该考虑使用DropDownList
控件:
<asp:DropDownList ID="ListBoxViewType" runat="server"....
并访问所选项目:
this.ListBoxViewType.SelectedValue
this.ListBoxViewType.SelectedItem.Text
this.ListBoxViewType.SelectedItem.Value