這是我的C#後端:C#/ ASP.NET嵌套Repeater確實發生了改變列表與新的母公司
protected void Page_Load(object sender, EventArgs args)
{
CaseEnt MyCase = McHenryLib.ICISAdapters.CaseAdapter.GetCaseRecordForCaseNumber(Globals.CaseNum);
List<Charge> charges = McHenryLib.ICISAdapters.ChargeAdapter.GetByCaseNumber(Globals.CaseNum);
rptChg.DataSource = charges;
rptChg.DataBind();
}
protected void rptChg_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
CaseEnt MyCase = McHenryLib.ICISAdapters.CaseAdapter.GetCaseRecordForCaseNumber(Globals.CaseNum);
List<Charge> charges = McHenryLib.ICISAdapters.ChargeAdapter.GetByCaseNumber(Globals.CaseNum);
if (charges != null && charges.Count > 0)
{
List<Sentence> sentences = new List<Sentence>();
foreach (Charge chg in charges)
{
Repeater rptSen = (Repeater)(e.Item.FindControl("rptSen"));
sentences.AddRange(McHenryLib.ICISAdapters.SentenceAdapter.GetByChargeObjectID(chg.ChargeObjectID));
if (sentences != null && sentences.Count > 0)
{
List<SentenceDisposition> disps = new List<SentenceDisposition>();
foreach (Sentence sen in sentences)
{
Repeater rptDisp = (Repeater)(e.Item.FindControl("rptDisp"));
disps.AddRange(McHenryLib.ICISAdapters.SentenceDispositionAdapter.GetDispositionsBySentenceOID(sen.SentenceID));
rptDisp.DataSource = disps;
rptDisp.DataBind();
}
}
rptSen.DataSource = sentences;
rptSen.DataBind();
}
}
}
這是我的ASP.NET前端:
<asp:Repeater ID="rptChg" runat="server" OnItemDataBound="rptChg_ItemDataBound">
<ItemTemplate>
<br />
<table class="chg">
<tr>
<th>Count <%#Eval("Counts") %></th>
</tr>
</table>
<!--Builds the Charges Table-->
<table class="chg">
<tr>
<th>Charge Date</th>
<th>Statute</th>
<th>Description</th>
<th>Disposition/Manner</th>
</tr>
<tr>
<td><%#Eval("ChargeDate")%></td>
<td><%#Eval("Statute")%></td>
<td><%#Eval("StatuteDesc")%></td>
<td><%#ChgCode(Eval("Disposition"))%></td>
</tr>
</table>
<!--Builds the Sentences Table-->
<table class="sen">
<asp:Repeater ID="rptSen" runat="server">
<HeaderTemplate>
<th colspan="3">Sentences</th>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("SentenceDate")%></td>
<td><%#Eval("TypeDesc")%></td>
<td><%#ZeroToNull(Eval("UnitTerm"))%> <%#ZeroToNullMoney(Eval("Amount"))%> <%#Eval("UnitTypeDesc")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
我試圖讓Sentences表爲每個Charge表的新實例重新填充,並帶有嵌套中繼器。然而,我嘗試了幾種不同的解決方案,但是每次Sentences表只是將相同的數據從第一次充電到所有這些數據。
我已經通過代碼幾次,我注意到,當它到DataBind第二個Sentences表,中繼器的ClientID不會改變,這使我認爲它不是滾動了一個新的實例中繼器,而不是每次重複相同的數據。
我的問題是:有沒有辦法讓它手動滾動一個新的順序ClientID,以便它每次綁定到正確的中繼器?或者我完全用錯誤的方式來解決這個問題?
這是殺害數據庫服務器。如果您讓他們成爲網頁課程的成員,MyCase和費用可以檢索一次。在頁面加載事件中填充它們,然後在數據綁定事件中使用它們。儘管MyCase似乎並未被數據綁定使用。 –