ZeeeeeV
ZeeeeeV

Reputation: 381

ASP.NET C# DataTable DropDownList Issue

I have a datatable/source binded to a drop down list in ASP.NET C#.

I am trying to return the selected drop down list value using:

dropdownlist.Text

However, this just returns the first list value. How can i get it to return the selected drop down list value?

Upvotes: 0

Views: 487

Answers (3)

Bilal lilla
Bilal lilla

Reputation: 658

Dropdown can return only one value. For list either you need to customize the dropdown or you need to find third party control to do that.

if You want to do it with 3rd party controls. you can try this


if you want to customize dropdown then view these
1 2

Upvotes: 0

nunespascal
nunespascal

Reputation: 17724

The dropdownlist.Text property should work.

Make sure that you are not binding the list again on Page_Load. This would reset the SelectedValue to the first value.

Use code like

if(!IsPostBack)
{
   //DataBind dropdownlist
}

Upvotes: 2

MarcinJuraszek
MarcinJuraszek

Reputation: 125620

Use DropDownList.SelectedValue property instead.

Upvotes: 0

Related Questions