Manoj Chowdary
Manoj Chowdary

Reputation: 97

How to get the dropdownlistselectedid in asp.net

var countries = context.MasterCountries.ToList();
ddlcountry.DataSource = countries;
ddlcountry.DataTextField = "Description";
ddlcountry.DataValueField = "Id";
ddlcountry.DataBind();

<asp:DropDownList runat="server" ID="ddlcountry" CssClass="textbox textbox-reg" />

int countryid = ddlcountry.SelectedIndex;

I am trying to get the id of the company but it's not working.

Upvotes: 0

Views: 67

Answers (1)

Amiram Korach
Amiram Korach

Reputation: 13296

Try that:

int countryid = int.Parse(ddlcountry.SelectedValue);

Upvotes: 1

Related Questions