asp.net repeater动态合并列

时间:2015-05-02 07:00:47

标签: asp.net merge repeater

我的ASP.net页面中有一个转发器。我想合并具有相同文本的列。这应该在绑定数据表时动态发生。我为此搜索了很多。但是,没有成功。我怀疑是否可以使用中继器。我还想提一下,每行还有图像按钮和复选框。

这是我的转发器来源: -

<asp:Repeater ID="rpt1" runat="server" onitemcommand="rpt1_ItemCommand">
        <HeaderTemplate>
            <table border="1" cellpadding="10" width="50%">
            <tr>
                <th>Item Name</th>
                <th>As On</th>
                <th>Price</th>
                <th></th>
                <th></th>
            </tr>
        </HeaderTemplate>
        <ItemTemplate>

            <tr>
                <td>
                    <asp:Label ID="lblRelayName" runat="server" Text='<%# Eval("ItemName") %>'></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblTimeFrom" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblPrice" runat="server" Text='<%# Eval("Price") %>'></asp:Label>
                </td>
                <td>
                    <asp:ImageButton ID="imgBtnStatus" runat="server" 
                        ImageUrl="~/img/btnGet.jpg" 
                        CommandName="Change"  style="width: 36px; border-width: 0px; margin-top: -4px; vertical-align: middle;" />
                </td>
                <td>
                    <asp:CheckBox ID="chkStatus" runat="server" Checked="true" />
                </td>
            </tr>

        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>

        </asp:Repeater>

这就是我填写转发器的方式: -

protected void Page_Load(object sender, EventArgs e)
{
    rpt1.DataSource = GetData();
    rpt1.DataBind();
}

private DataTable GetData()
{
    DataTable dt = new DataTable();
    dt.Columns.Add("ItemName");
    dt.Columns.Add("Date");
    dt.Columns.Add("Price");

    DataRow dr = dt.NewRow();
    dr["ItemName"] = "Orange";
    dr["Date"] = "01/01/2015";
    dr["Price"] = "50";
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr["ItemName"] = "Orange";
    dr["Date"] = "02/01/2015";
    dr["Price"] = "51";
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr["ItemName"] = "Orange";
    dr["Date"] = "03/01/2015";
    dr["Price"] = "55";
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr["ItemName"] = "Apple";
    dr["Date"] = "01/01/2015";
    dr["Price"] = "95";
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr["ItemName"] = "Apple";
    dr["Date"] = "03/01/2015";
    dr["Price"] = "98";
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr["ItemName"] = "Banana";
    dr["Date"] = "01/01/2015";
    dr["Price"] = "48";
    dt.Rows.Add(dr);

    return dt;
}

0 个答案:

没有答案