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>

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.


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

Non-existent submodule mentioned in git error

git git-submodules

Git is telling me I can't add some files to the index because they are in a submodule. I think it's true that these files were once in a submodule, but I can't find any indication that they still ...

Print and update a matrix in-place

python curses urwid

I have a matrix represented as a list of lists (but can easily change this representation if it would help). I will be updating this matrix as the program runs. I would like to have the matrix disp...