我必须动态填充文件后面的代码中的选择。我能够从Page_load执行此操作,但无法通过静态Web方法执行此操作。它说" 访问非静态字段需要一个对象引用..."
<div style="margin-left: 24%; display: inline-block" runat="server">
<label style="margin-top: 3%">Select Voice Product</label>
<button type="button" style="margin-top: 3%;" class="qual toDisable" id="btnAddVoicetToSelected" onclick="btnAddVoice()">Add Voice</button>
<select id="selectedVoiceProducts" runat="server" name="VoiceProducts" style="margin-top: 3%;">
<option label="Select Voice Product" value="-1">Select</option>
</select>
</div>
代码背后:
[WebMethod]
pulic static void Populate(){
selectedVoiceProducts.Items.Add(new ListItem("SomeItem","SomeValue");//error here
}
答案 0 :(得分:1)