2
我有這樣的控制:如何在Page_Load方法中獲取參數?
<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的回發應計及此功能被激發:
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方法中的下拉列表中選擇項目?
預先感謝您。