【发布时间】:2016-04-30 04:32:12
【问题描述】:
我有这个控制:
<asp:DropDownList ID="ddlPaging" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlPaging_SelectedIndexChanged">
</asp:DropDownList>
这里我如何将服务器端的数据绑定到上面的控件:
ddlPaging.Visible = true;
ddlPaging.DataSource = Enumerable.Range(0, features.Count()).ToList();
ddlPaging.DataBind();
当我在 DropDownList postBack 中进行选择并触发此功能时:
protected void Page_Load(object sender, EventArgs e)
{
string controlId= this.FindControl(this.Request.Params.Get("__EVENTTARGET")).ID
//always empty
string ctrlarg1 = this.Request.Params.Get("__EVENTARGUMENT");
string ctrlarg2 = Request.Form["__EVENTARGUMENT"];
string ctrlarg3 = Request.Params["__EVENTARGUMENT"];
string ctrlarg4 = this.Request["__EVENTARGUMENT"];
string ctrlarg5 = this.Request.Params.Get("__EVENTARGUMENT");
if (!isPaging)
{
ddlPaging.Visible = true;
ddlPaging.DataSource = Enumerable.Range(0, features.Count()).ToList();
ddlPaging.DataBind();
}
}
当 Page_Load 方法被触发时,我需要在下拉列表中获取所选项目。
我试试这个方法:
string ctrlarg1 = this.Request.Params.Get("__EVENTARGUMENT");
string ctrlarg2 = Request.Form["__EVENTARGUMENT"];
string ctrlarg3 = Request.Params["__EVENTARGUMENT"];
string ctrlarg4 = this.Request["__EVENTARGUMENT"];
string ctrlarg5 = this.Request.Params.Get("__EVENTARGUMENT");
但结果为空。
当我以这种方式获得控件 ID 时:
string controlId= this.FindControl(this.Request.Params.Get("__EVENTTARGET")).ID
效果很好!
所以我的问题是,如何在 Page_Load 方法的下拉列表中获取选定项目?
【问题讨论】:
标签: c# asp.net pageload asp.net-controls