简体   繁体   中英

request.form for dropdownlist value

i need to get value of selected item of dropdownlist using Post Method (request.form).

request.form["DropDownList"];

how can i get selectedvalue ,selectedindex or selecteditem.text ....

试试这个(假设你的DropDownList的ID是DropDownList1

Request.Form[DropDownList1.UniqueID]

这样您就可以获得选定的值。

string value=Request.Form["DropDownList1"]; 

With the method you are requesting. It can't be done.

That being said. If you are doing a Cross Page Postback, then that is one case where you can access the previous pages objects in it. Otherwise, if you don't have that type of control, then, you likely can't get to them.

In simple terms, you'd do a form on Page1.aspx like so

<form PostBackUrl="~/Page2.aspx" runat="server" id="frm">

On Page2.aspx, along with some other code, using the PreviousPage , you can do something like so:

((DropDownList)Page.PreviousPage.FindControl("DropDownList")).SelectedValue;

References:

How to: Post ASP.NET Web Pages to a Different Page

Cross-Page Posting in ASP.NET Web Pages

You can obtains the value from

Request.Form["DropDownList1"]

but if the ID of the drop down list is not static, you can do this..

Create a temporary static variable in some global.cs file

public class Global
{
    public static string ddlID="";
}

and in .aspx.cs file where the drop down list is place.

Global.ddlID = DropDownList1.UniqueID

and on post pack

if (this.Request.Form["__EVENTTARGET"] == Globals.ddlID) {
//Perform action here, This postback is caused by **DropDownList1**
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM