开发者

How do I get selected value from select box using Request.Form?

开发者 https://www.devze.com 2023-01-06 16:06 出处:网络
I\'m submitting a form and need to collect the data. Following this example, I\'m trying to retrieve the value I selected in a select box.

I'm submitting a form and need to collect the data.

Following this example, I'm trying to retrieve the value I selected in a select box.

The pro开发者_如何学Goblem is, the select box does not have the attribute 'name'.

<asp:DropDownList runat="server" ID="countySelect" CssClass="ddlCountySelect" DataValueField="kommunekode" DataTextField="kommune" ></asp:DropDownList>

How can I then retrieve its selected value?

This is the code I'm trying to use:

        if (Request.Form.Count > 0)
            lblTest.Text = Convert.ToString(Context.Request.Form["countySelect"]);
        else
            lblTest.Text = "nada";

The result is blank.


If your DDL is inside a naming container, you'll need to use the UniqueID property of the control. Try Context.Request.Form[countySelect.UniqueID]. (I'm pretty sure UniqueID is the one you want but if it doesn't work, try ClientID). Also, you could hook up the debugger and take a look at everything in Request.Form to see what the contents are and perhaps that could help you.

Is this being processed on the same page as the DDL is on? If so you can just use countySelect.SelectedValue. Since you have Context.Request rather than just Request, I'm guessing it is not the same page though.

0

精彩评论

暂无评论...
验证码 换一张
取 消