我正在尝试创建一个下拉列表,以过滤页面上的搜索结果。字符串selectedText将成为我过滤结果的依据,但是我不断收到错误消息“名称'ddlCategory'在当前上下文中不存在”,我不确定这是怎么回事。
<asp:dropdownlist id="ddlCategory" runat="server" autopostback="true" onselectedindexchanged="OnSelectedIndexChanged">
<asp:listitem text="Email" value="1"></asp:listitem>
<asp:listitem text="Title" value="2"></asp:listitem>
<asp:listitem text="Date" value="3"></asp:listitem>
<asp:listitem text="Department" value="4"></asp:listitem>
<asp:listitem text="Location" value="5"></asp:listitem>
</asp:dropdownlist>
````````````````````````````````````````````````````````````````
public class DataModel : PageModel
{
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
string selectedText = ddlCategory.SelectedItem.Text;
}
}