0

変数を宣言し、asp のドロップダウン リストからデータを入力しました。ただし、ページロード時にラベルは入力されません。ドロップダウンの値を変更するとラベルが入力されます。そのため、最初はページの読み込み時ではなく、変数がラベルで機能しています。

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

    Dim strDataCollection As String = ddlDataCollection.Text
    Dim strYear As String = DdlYear.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

    If strTeachingGroup = "Select All" Then
        lblHeaderTeachingGroup.Visible = False
    Else
        lblHeaderTeachingGroup.Visible = True
    End If

    If strSubgroup = "Select All" Then
        lblHeaderSubroup.Visible = False
    Else
        lblHeaderSubroup.Visible = True
    End If

End Sub

私のラベルのaspは次のとおりです。

<div class="centeronpage">
          <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>
</div>

回答を編集

以下に示すように、次の PreRender を作成しました。次に、ラベル要素の 1 つに含める OnPreRender="Page_PreRender"と、これが prerender をトリガーするように見えました。

Protected Sub Page_PreRender(sender As Object, e As EventArgs)

    Dim strDataCollection As String = ddlDataCollection.Text
    Dim strYear As String = DdlYear.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

End Sub

編集 - DDL バインディング

<asp:Label ID="lblHeaderYear" runat="server" Text="" CssClass="header" OnPreRender="Page_PreRender"></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>
4

1 に答える 1