tags:

views:

19

answers:

2

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 problem 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.

A: 

http://msdn.microsoft.com/en-us/library/ms525985(VS.90).aspx

Andrew
The problem is still that `asp:DropDownList` does not have a property `NAME`. Henche why I can't retrieve selected item from DDL.
Steven
+1  A: 

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.

rchern
The problem is that the Unique ID .NET generates is `ctl00_MainContentPlaceHolder_RightContentPlaceHolder_countySelect` - so I can't fetch the data by using just `countySelect`. And yes, the data is being processed on the same page.
Steven
Yes, that is how UniqueID generates the id, but take a look at what is in Request.Form. If it is on the same page though, why not just use countySelect.SelectedValue?
rchern