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.
精彩评论