0

我的 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 + "\")";
                            }
4

1 回答 1

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
于 2012-08-10T01:51:12.340 回答