How can I get the selected dropdown item when the first page loads?

I am looking for a solution to get the first selected item in a DropDownList. And I want to get it when the page loads for the first time.

Thanks in advance.

Edit: I call this method in Load-event, but ddlNiveau2 remains empty. I think ddlNiveau1.SelectedValue is not available.

public void FillListNiveau2()
{
    ddlNiveau2.Items.Clear();
    foreach (var item in dBAL.GetListNiveau2(ddlNiveau1.SelectedValue))
    {
        ddlNiveau2.Items.Add(item.ToString());
    }
    RemoveDuplicateItems(ddlNiveau2);
}
+3
source share
4 answers

There is DataBound eventone that starts after the data is tied to a drop-down list. When you assign a dataSource to a drop-down list, you need to select the item after all the rows bound to the drop-down menu

protected void DropDownList1_DataBound(object sender, EventArgs e)
{
    DropDownList1.SelectedValue // store it in some variable
}
+12
source

You can get the selected value, for example

string selected = drp.SelectedItem.Text;

Or

string selected = drp.SelectedItem.Value;

, Selected, , SelectedIndex Text/Value

+4

Page_Load:

if (!Page.IsPostBack)
{

    // Load list items ..
    dropDownList.SelectedIndex = 0;

}

. DropDownList.

0

, , dropdown. SelectedValue. , , ,

0

All Articles