0

我已经根据下拉文本声明了变量:

    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

然后我调用了这些变量以显示在一系列标签中。

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

但是,在页面加载时,仅lblHeaderYear填充标签文本,而不填充其余标签。然而,当我从下拉列表中进行选择时,它们都显示正常。

这是前面的asp:

      <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>
4

1 回答 1

1

看起来您没有对所有下拉列表框使用“SelectedItem.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

你想要:

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
于 2013-05-03T11:18:16.050 回答