English 中文(简体)
• 如何增加网络用户控制以重复使用
原标题:How to add web user controls to repeater

设想:

  • UsrControl: Customsuser control, which includes a text Box and a button, rederally (in one line).

  • UsrControlContainer: Customsuser control, which should be found over UsrControlbject (each Object in seperate line, so the Seperator model will may be <br />. 这一控制还包含一个纽芬兰州,为收集工作增加了新的乌斯托·科蒂尔。

我的法典:

<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"/>
<asp:Repeater ID="rptExample" runat="server">
    <ItemTemplate>

    </ItemTemplate>
    <SeparatorTemplate><br /></SeparatorTemplate>
</asp:Repeater>

而且:

protected void Button1_Click(object sender, EventArgs e)
{
    rptExample.DataSource = new List<UsrControl> {new UsrControl(), new UsrControl()};
    rptExample.DataBind();
}

简单问题——我应在<条码>中说明什么?

Edit——我还要通过一些参数,然后才提交UsrControl。

最佳回答
<asp:Repeater ID="rptExample" runat="server">
     <ItemTemplate>
          <uc:UsrControl runat="server" />
     </ItemTemplate>
     <SeparatorTemplate><br /></SeparatorTemplate>
</asp:Repeater>

protected void Button1_Click(object sender, EventArgs e)
{
    rptExample.DataSource = Enumerable.Range(0, 2);
    rptExample.DataBind();
}
问题回答

回答问题之后。 你可以在项目DataBound活动中捕获每一个具有约束力的物体。 例如,一如使用,将整个物体作为用户控制财产。

protected void PersonesRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        PersonLine line = (PersonLine)e.Item.FindControl("Person1");
        line.Person = e.Item.DataItem as Osoba;
    }
}

在座各位还必须在您的记忆中增加活动手:

<asp:Repeater runat="server" ID="PersonesRepeater" OnItemDataBound="PersonesRepeater_ItemDataBound"><ItemTemplate>
        <my:Person ID="Person1" runat="server" />
    </ItemTemplate>
</asp:Repeater>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签