VB.net dropdown list value populated in variable rather than text

I have a dropdown list populated as follows:

<asp:DropDownList ID="ddlSubgroup" runat="server" cssclass="dropdown" style="font-size: 11px" AutoPostBack="True">
        <asp:ListItem Selected="True">Select All</asp:ListItem>
        <asp:ListItem Value="GenF">Girls</asp:ListItem>
        <asp:ListItem Value="GenM">Boys</asp:ListItem>
-----snip

In my page load procedure I have declared a variable and then use that variable to update the contents of a label:

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim strSubgroup As String = ddlSubgroup.Text

    lblHeaderSubroup.Text = " " & strSubgroup

However, this results in the dropdown listitem value eg "GenF" displaying in my label and not the text eg Girls as expected.

Answers


Try referring to the lblHeaderSubroup.SelectedItem.Text property instead of the object itself.

This could be where you're experiencing the issue.


Use ddlSubgroup.SelectedItem.Text property.

lblHeaderSubroup.Text = ddlSubgroup.SelectedItem.Text

Need Your Help

How to know whether a URL request for my website is from browser or from a automated program

java httpwebrequest httprequest webpage spam-prevention

My requirement is to know whether a request to my webpage is a genuine request (through browser ) or a automated request that is generated through some Java program. Where can I differentiate the r...

MVC view path from VisualStudio fails

asp.net asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing url-routing

When I right click on my view file (RetrieveReport.cshtml) and select "Properties" I find the "Browse to URL" property has this value: "~/Reports/HtmlReport/RetrieveReport"

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.