VB.net Labels not populated from dropdown variable data on pageload, but update when dropdowns change

I have declared variables based on dropdown text:

    Dim strDataCollection As String = ddlDataCollection.Text
    Dim strYear As String = DdlYear.SelectedItem.Text
    Dim strSubject As String = DdlSubject.Text
    Dim strTeachingGroup As String = DdlTeachingGroup.Text
    Dim strSubgroup As String = ddlSubgroup.SelectedItem.Text

Then I've called those variables to display in a series of labels.

    lblHeaderYear.Text = "Year " & strYear
    lblHeaderDataCollection.Text = " " & strDataCollection
    lblHeaderSubject.Text = " " & strSubject
    lblHeaderTeachingGroup.Text = " " & strTeachingGroup
    lblHeaderSubroup.Text = " " & strSubgroup

However, on page load only the lblHeaderYear label text is populating, but not the rest of the labels. Yet when I make a selection from the dropdown lists then they all display ok.

Here is the asp in front of this:

      <div style="width:100%; height: 100%;">

        <asp:Label ID="lblDataCollection" runat="server" Text="Data Collection: " cssclass="label"></asp:Label>
        <asp:DropDownList ID="ddlDataCollection" runat="server" DataSourceID="DsDataCollection" DataTextField="DataCollection" DataValueField="DataCollection" CssClass="dropdown" AutoPostBack="True">
        </asp:DropDownList>

        <asp:SqlDataSource ID="DsDataCollection" runat="server" ConnectionString="<%$ ConnectionStrings:MaltingsConnectionString %>" SelectCommand="SELECT DISTINCT DataCollection FROM Subject ORDER BY DataCollection"></asp:SqlDataSource>
          <asp:Label ID="lblYear" runat="server" CssClass="label" Text="Year: "></asp:Label>
        <asp:DropDownList ID="DdlYear" runat="server" AutoPostBack="True" CssClass="dropdown">
            <asp:ListItem Selected="True">11</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
        </asp:DropDownList>
          <asp:Label ID="lblSubject" runat="server" CssClass="label" Text="Subject: "></asp:Label>
        <asp:DropDownList ID="DdlSubject" runat="server" DataSourceID="DsSubject" DataTextField="Subject Name" DataValueField="Subject Name" AutoPostBack="True" CssClass="dropdown">
        </asp:DropDownList>
        <asp:SqlDataSource ID="DsSubject" runat="server" ConnectionString="<%$ ConnectionStrings:MaltingsConnectionString %>" SelectCommand="SELECT DISTINCT Subject.Name AS 'Subject Name', CASE WHEN Subject.Name LIKE 'English' OR Subject.Name LIKE 'English iGCSE' OR Subject.Name LIKE 'Mathematics' THEN 0 ELSE 1 END AS Ordering, Subject.DataCollection AS Expr1 FROM Student INNER JOIN Subject ON Student.UPN = Subject.UPN WHERE (Student.StuYear = 11) AND (Subject.DataCollection LIKE 'March 2013') ORDER BY Ordering, 'Subject Name'"></asp:SqlDataSource>
        <asp:Label ID="LblTeachingGroup" runat="server" Text="Teaching Group: " CssClass="label"></asp:Label>
        <asp:DropDownList ID="DdlTeachingGroup" runat="server" DataSourceID="DsTeachingGroup" DataTextField="Teaching Group" DataValueField="Teaching Group" AutoPostBack ="true" CssClass="dropdown">
            <asp:ListItem Selected="True" Value="Select All">Select All</asp:ListItem>
        </asp:DropDownList>

        <br />
        <asp:SqlDataSource ID="DsTeachingGroup" runat="server" ConnectionString="<%$ ConnectionStrings:MaltingsConnectionString %>" SelectCommand="SELECT 'Select All' AS 'Teaching Group', 0 AS SortOrder UNION SELECT DISTINCT Subject.TeachingGroup AS 'Teaching Group', 1 AS SortOrder FROM Student INNER JOIN Subject ON Student.UPN = Subject.UPN WHERE (Subject.Name LIKE 'English') AND (Student.StuYear = 11) ORDER BY SortOrder, 'Teaching Group'"></asp:SqlDataSource>

        <asp:Label ID="lblSubgroup" runat="server" cssclass="label" style="font-size: 11px" Text="Subgroup: "></asp:Label>
        <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>
            <asp:ListItem Value="High">High Attainers</asp:ListItem>
            <asp:ListItem Value="Middle">Middle Attainers</asp:ListItem>
            <asp:ListItem Value="Low">Low Attainers</asp:ListItem>
            <asp:ListItem Value="PPYes">Pupil Premium</asp:ListItem>
            <asp:ListItem Value="PPNo">Non-Pupil Premium</asp:ListItem>
            <asp:ListItem Value="FSMYes">Free School Meals</asp:ListItem>
            <asp:ListItem Value="FSMNo">Non-Free School Meals</asp:ListItem>
            <asp:ListItem Value="SENYes">Special Educational Needs</asp:ListItem>
            <asp:ListItem Value="SENNo">Non-Special Educational Needs</asp:ListItem>
            <asp:ListItem Value="SENS">Statemented</asp:ListItem>
            <asp:ListItem Value="SENNoS">Non-Statemented</asp:ListItem>
            <asp:ListItem Value="SENAYes">School Action</asp:ListItem>
            <asp:ListItem Value="SENANo">Non-School Action</asp:ListItem>
            <asp:ListItem Value="SENPYes">School Action Plus</asp:ListItem>
            <asp:ListItem Value="SENPNo">Non-School Action Plus</asp:ListItem>
            <asp:ListItem Value="EALYes">English as Additional Language</asp:ListItem>
            <asp:ListItem Value="EALNo">Non-English as Additional Language</asp:ListItem>
            <asp:ListItem Value="LACYes">Looked After Children</asp:ListItem>
            <asp:ListItem Value="LACNo">Non-Looked After Children</asp:ListItem>
            <asp:ListItem Value="GandTYes">Gifted and Talented</asp:ListItem>
            <asp:ListItem Value="GandTNo">Non-Gifted and Talented</asp:ListItem>
            <asp:ListItem Value="GiftedYes">Gifted</asp:ListItem>
            <asp:ListItem Value="GiftedNo">Non-Gifted</asp:ListItem>
            <asp:ListItem Value="TalentYes">Talented</asp:ListItem>
            <asp:ListItem Value="TalentNo">Non-Talented</asp:ListItem>
        </asp:DropDownList>
          <br />
          <br />
          <asp:Label ID="lblHeaderYear" runat="server" Text="" CssClass="header"></asp:Label>
          <asp:Label ID="lblHeaderDataCollection" runat="server" Text="" CssClass="header"></asp:Label>
          <asp:Label ID="lblHeaderSubject" runat="server" Text="" CssClass="header"></asp:Label>
          <asp:Label ID="lblHeaderTeachingGroup" runat="server" Text="" CssClass="header"></asp:Label>
          <asp:Label ID="lblHeaderSubroup" runat="server" Text="" CssClass="header"></asp:Label>
          <br />
          <br />
       </div>

Answers


it looks like you're not using the 'SelectedItem.Text' property for all the dropdownlist boxes. Instead of

Dim strDataCollection As String = ddlDataCollection.Text
Dim strYear As String = DdlYear.SelectedItem.Text
Dim strSubject As String = DdlSubject.Text
Dim strTeachingGroup As String = DdlTeachingGroup.Text
Dim strSubgroup As String = ddlSubgroup.SelectedItem.Text

Do you want:

Dim strDataCollection As String = ddlDataCollection.SelectedItem.Text
Dim strYear As String = DdlYear.SelectedItem.Text
Dim strSubject As String = DdlSubject.SelectedItem.Text
Dim strTeachingGroup As String = DdlTeachingGroup.SelectedItem.Text
Dim strSubgroup As String = ddlSubgroup.SelectedItem.Text

Need Your Help

Debugging JQuery Mobile on my Android

css debugging mobile

I have an application that I want to debug through my phone. I need to edit some css, (or see why its looking how it is)