我真的很困惑。为此,我整天都感到困惑,但仍然无法修复。我进行了一个(Repeater.ASCX)Web用户控制(内部重复器),然后将其拖动aspx page(info.aspx)这样。
<uc1:Repeater runat="server" ID="Repeater" />
这是用户控制代码。
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Repeater.ascx.cs" Inherits="DBG.Website.Billing.Repeater" %>
<asp:Repeater ID="repeaterInvoicesPaid" OnItemCommand="ClientNameClicked" runat="server">
<HeaderTemplate>
<table id="PaidInvoicesTable" cellspacing="0" cellpadding="0" style="width: 100%; font-size: 11px; border-right-width: 0; border-bottom-width: 0;"
class="dxgvControl grid dxgvTable">
<thead>
<tr>
<td style="width: 150px;" class="dxgvHeader">Invoice #
</td>
<td style="width: 150px;" class="dxgvHeader">Client Name
</td>
<td style="width: 150px;" class="dxgvHeader">Invoice Date
</td>
<td style="width: 150px;" class="dxgvHeader">Due Date
</td>
<td style="width: 150px;" class="dxgvHeader">Total
</td>
<td style="width: 150px;" class="dxgvHeader">Payment Method
</td>
<td style="width: 150px;" class="dxgvHeader">Status
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr class="dxgvDataRow">
<td class="dxgv">
<asp:Label ID="lblInvoiceID" Text='<%#Eval("InvoiceID")%>' runat="server" />
</td>
<td class="dxgv">
<asp:LinkButton ID="btnClientName" CommandName="NameClicked" Text='<%#Eval("ClientName")%>' CommandArgument='<%#Eval("InvoiceReapterCustomerID") %>' runat="server"/>
</td>
<td class="dxgv">
<asp:Label ID="lblAddedDate" Text='<%#Eval("AddedDateAndTime")%>' runat="server" />
</td>
<td class="dxgv">
<asp:Label ID="lblCloseDate" Text='<%#Eval("CloseDateOnly") %>' runat="server" />
</td>
<td class="dxgv">
<asp:Label ID="lblRecurringCharge" Text='<%#Eval("RecurringCharge") %>' runat="server" />
</td>
<td class="dxgv">
<asp:Label ID="lblPaymentMethodID" Text='<%#Eval("PaymentMethodIDInvoices")%>' runat="server" />
</td>
<td class="dxgv">
<asp:Label ID="lblStatus" ForeColor="Green" Text=' <%#Eval("StatusType") %>' runat="server" />
</td>
<td class="dxgv">
<asp:Label ID="lblCustomerid" Visible="false" Text=' <%#Eval("InvoiceReapterCustomerID") %>' runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
现在我的问题是我要绑定info.cs文件中的Web用户控制的中继器,但我没有如何在info.cs上获取用户控制和中继器ID并绑定它。
注意:我需要使用dataSource(list)从info.cs的方法返回的中继器。
请帮忙。谢谢。
您可以在控件中进行公开方法并从页面上调用。
在ASCX
中public void BindRepeater()
{
//.....
repeaterInvoicesPaid.DataSource = datatableOrDataSet;
repeaterInvoicesPaid.DataBind();
}
在ASPX
中uc1.BindRepeater();
通常对于香草ASP.NET,如果指定一个ID,并且runat =" server"属性,则可以从ASPX页面的代码访问控件。重要的是要访问帖子初始化控件的创建位置 - 您的最佳选择将是在Onload事件中。
您要记住的是,当您设置DataSource/itemsSource时,您必须调用.bind()或.databind()方法以进行实际绑定。