如何用转发器重复10次相同的代码?

时间:2010-02-16 20:49:57

标签: asp.net repeater

<asp:Repeater id="rptExcelField" runat="server">
    <HeaderTemplate>
        <table style="width:100%;" id="mainTable">
    </HeaderTemplate>         
    <ItemTemplate>
        <tr>
            <td class="style1">
                <asp:Label ID="lblField" runat="server" Text="Polje:" CssClass="textType"></asp:Label>
            </td>                
            <td class="style2">
                <asp:TextBox ID="txtField" runat="server" Width="436px" MaxLength="45" 
                    CssClass="inputType"></asp:TextBox>
                <asp:DropDownList ID="ddlInputType" runat="server" oninit="ddlInputType_Init" 
                    AutoPostBack="True" 
                    onselectedindexchanged="ddlInputType_SelectedIndexChanged">                        
                </asp:DropDownList>     
            </td>
            <td class="style3">
                <asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtName"
                    ErrorMessage="*" CssClass="validator"></asp:RequiredFieldValidator>
            </td>
        </tr>
    </ItemTemplate>         
    <FooterTemplate>
        </table>
    </FooterTemplate>         

如何使用转发器重复相同代码10次?

1 个答案:

答案 0 :(得分:5)

实际上,您只需要将转发器绑定到包含10个项目的内容中。也许不是简单地在屏幕上转储10次迭代的最佳方法,而是专门回答你的问题:

代码隐藏:

protected void Page_Load(object sender, EventArgs e)
{
    List<int> data = new List<int>();
    for(int i=0; i<10; i++)
    {
        data.Add(i);
    }

    rptExcelField.DataSource = data;
    rptExcelField.DataBind();
}