2012-08-10 107 views
0

我有我的p1.aspx此下拉:如何將.aspx下拉列表的值傳遞給.asmx.cs?

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

回答

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 
相關問題