[英]How to bind repeater of Web User Control
I am really confused .Wasted 1 full day for it but still not able to fix .I made a (Repeater.ascx)web user control(having Repeater inside) and then drag it on aspx page(Info.aspx) like this. 我真的很困惑。为此浪费了整整1天的时间,但仍然无法修复。我做了一个(Repeater.ascx)web用户控件(内部装有Repeater),然后将其拖动到aspx页面(Info.aspx)上。
<uc1:Repeater runat="server" ID="Repeater" />
This is user control code. 这是用户控制代码。
<%@ 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>
Now my problem is that i want to bind the repeater of web user control inside info.cs file but i do not how to get user control and repeater id on info.cs and bind it . 现在我的问题是我想将Web用户控件的转发器绑定到info.cs文件中,但是我不希望在info.cs上获取用户控件和转发器ID并将其绑定。
Note:i need to bind repeater with datasource(List) return from a info.cs's method. 注意:我需要将转发器与从info.cs方法返回的数据源(列表)绑定。
Please Help . 请帮忙 。 Thank you. 谢谢。
You can make a public method in your control and call it from the page. 您可以在控件中创建一个公共方法,然后从页面中调用它。
In ASCX 在ASCX中
public void BindRepeater()
{
//.....
repeaterInvoicesPaid.DataSource = datatableOrDataSet;
repeaterInvoicesPaid.DataBind();
}
In ASPX 在ASPX中
uc1.BindRepeater();
Typically for vanilla ASP.NET if you specify an ID and the runat="server" attribute you can access the control from the code of the aspx page. 通常,对于香草ASP.NET,如果指定ID和runat =“ server”属性,则可以从aspx页的代码访问控件。 It's important to access post initialize where the controls get created - your best choice would be in the OnLoad event. 访问在控件创建位置进行初始化后的操作很重要-最好的选择是在OnLoad事件中。
What you have to remember is when you set the datasource/itemssource, you have to call the .Bind() or .DataBind() method aftewards to do the actual binding. 您要记住的是,在设置数据源/项目源时,必须事后调用.Bind()或.DataBind()方法来进行实际的绑定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.