Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the selected text (not selected value) of an asp:dropdownlist in code behind using C#

I need to read in the code behind the selected text (not the value) in the dataTextField of a dropdownlist that is nested in a FormView.

Here is my DDL:

<asp:DropDownList ID="DDL1" runat="server" DataSourceID="SQL1" dataTextField="name" DataValueField="IDname" CausesValidation="True" ClientIDMode="Static">
</asp:DropDownList>

And here is my code behind:

protected void UpdateButton_Click(object sender, EventArgs e)
{     
      DropDownList DDL1 = FV1.FindControl("DDL1") as DropDownList;
      SQL3.UpdateParameters["ddlparam"].DefaultValue = DDL1.SelectedValue;
     // Possible to get the text corresponding to the selectedValue?  
}

So far so good. Now I want to get the text in the dataTextField corresponding to the selected value. Possible? and How?

like image 977
Gloria Avatar asked Sep 14 '25 11:09

Gloria


1 Answers

Grab the text of the selected item with:

DDL1.SelectedItem.Text
like image 84
Thomas Stringer Avatar answered Sep 17 '25 01:09

Thomas Stringer