2017-07-18 66 views
1

我正在嘗試更新此網站。我在舊風格生成的報告表所示:將ASP經典錶轉換爲ASP.NET直放站

Dim sTable = "<table class=""stat"">" 
sTable = sTable & "<thead><tr><th colspan=20><Status Report: " & Session("ProcessYear") & "</th></tr>" 

我轉換到這個中繼器,但我在一個不知如何以包括會話數據。我有:

<asp:Repeater id="Dashboard" runat="server"> 
<HeaderTemplate> 
    <table class="stat"> 
     <thead> 
      <tr><th colspan="20">Appeal Status Report: ???? </th></tr> 
... 

有些考生是asp:PlaceHolder,並且像<%# ((RepeaterItem)Container.Parent.Parent).DataItem %>(見Accessing parent data in nested repeater, in the HeaderTemplate),但我在一個無所適從被引用。

不幸的是,無法重構會話依賴關係。有什麼想法嗎?我對ASP.NET相當陌生。我的這個頁面的CodeFile在VB.NET中。

回答

1

您需要查看On Item Data Bound event,因此您可以在綁定過程中執行一些代碼隱藏工作。

您需要檢查項目對象,確定its a header row,然後訪問您的會話對象。

粗糙適應可能看起來像:

ASPX

<asp:Repeater id="Dashboard" runat="server" OnItemDataBound="ItemDataBound"> 
<HeaderTemplate> 
    <table class="stat"> 
     <thead> 
      <tr> 
       <th colspan="20"> 
        Appeal Status Report: <asp:Label ID="YourLabel"/> 
       </th> 
      </tr> 
     ... 
    ... 
... 

代碼隱藏

void ItemDataBound(Object Sender, RepeaterItemEventArgs e) 
{ 
    if (e.Item.ItemType == ListItemType.Header) 
    { 
     ((Label)e.Item.FindControl("YourLabel")).Text = Session["YourSession"]; 
    } 
} 

你也可以做的事情與頁腳,項目d在這裏交替的項目也是如此。