ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


Get the selected value of a DropDownList by returning the value stored in the forms collection. This allows you to turn EnableViewState off on a DropDownList and still easily retrieve the selected value


public static string GetSelectedValue(this System.Web.UI.WebControls.DropDownList ddl)
    return System.Web.HttpContext.Current.Request.Form[ddl.UniqueID];


string sValue = ddlSampleDropDown.GetSelectedValue();

Author: Jeremy Chapman

Submitted on: 18 mrt 2010

Language: C#

Type: System.Web.UI.WebControls.DropDownList

Views: 4340