2013-05-03 11 views
0

我已經聲明的變量:VB.net的標籤沒有從頁面加載下拉可變數據,但是更新填充時的下拉列表中更改基於下拉文本

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> 

回答

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 
+1

感謝@ 5uperdan,即得到了它。從數據庫填充一些下拉列表,以便它們可以很好地處理.text後綴,但那些手動定義的下拉列表需要selecteditem.text後綴,例如子組下拉列表。 – Matt 2013-05-07 07:56:08

相關問題