locked
Increase Heigh Of Repater Control RRS feed

Answers

  • User-335504541 posted

    Hi asp.ambur,

    Please try to use the following code:

    In aspx:

    <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
                    <HeaderTemplate>
                        <table border="1">
                            <tr>
                                <th>Grade</th>
                                <th>Pcs</th>
                                <th>Amount</th>
                            </tr>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr>
                            <td colspan="3">BatchNo:
                                <asp:Label ID="BatchNolb" runat="server" Text='<%# Eval("BatchNo") %>'></asp:Label>
                                DateOfIssue:<asp:Label ID="DateOfIssuelb" runat="server" Text='<%# Eval("DateOfIssue") %>'></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3">ItemName:<asp:Label ID="ItemNamelb" runat="server" Text='<%# Eval("ItemName") %>'></asp:Label>
                                Color:<asp:Label ID="Colorlb" runat="server" Text='<%# Eval("Color") %>'></asp:Label>
                            </td>
                        </tr>
                        <asp:Repeater ID="Repeater2" runat="server" OnItemDataBound="Repeater2_ItemDataBound">
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <%# Eval("Grade") %> 
                                    </td>
                                    <td>
                                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("Pcs") %>'></asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="Label3" runat="server" Text='<%# Eval("Amount") %>'></asp:Label>
                                    </td>
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                <tr  visible="false"  id="hiddenrow" runat="server">
                                    <td colspan="3">
                                    </td>
                                </tr>
                                <tr>
                                    <td>Total:
                                    </td>
                                    <td>
                                        <asp:Label ID="Label4" runat="server" Text=""></asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="Label5" runat="server" Text=""></asp:Label>
                                    </td>
                                </tr>
                            </FooterTemplate>
                        </asp:Repeater>
                    </ItemTemplate>
                </asp:Repeater>

    In behind code:

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                pscTotal = 0;
                amountTotal = 0;
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    Label BatchNolb = e.Item.FindControl("BatchNolb") as Label;
                    Label DateOfIssuelb = e.Item.FindControl("DateOfIssuelb") as Label;
                    Label ItemNamelb = e.Item.FindControl("ItemNamelb") as Label;
                    Label Colorlb = e.Item.FindControl("Colorlb") as Label;
                    //string connection = ConfigurationManager.ConnectionStrings["TestDbConnectionString"].ConnectionString;
                    //SqlConnection sqlCon = new SqlConnection(connection);
                    //string sqlStr = "Select Grade,Pcs,Amount from Table1 where BatchNo='" + BatchNolb.Text
                    //    + "'and DateOfIssue='" + DateOfIssuelb.Text
                    //    + "'and ItemName='" + ItemNamelb.Text
                    //    + "'and Color='" + Colorlb.Text
                    //    + "'";
                    //SqlDataAdapter da = new SqlDataAdapter(sqlStr, sqlCon);
                    //DataSet ds = new DataSet();
                    //da.Fill(ds, "Grouped");
                    DataTable dt = new DataTable();
                    dt.Columns.Add("BatchNo");
                    dt.Columns.Add("DateOfIssue");
                    dt.Columns.Add("ItemName");
                    dt.Columns.Add("Color");
                    dt.Columns.Add("Grade");
                    dt.Columns.Add("Pcs");
                    dt.Columns.Add("Amount");
                    dt.Rows.Add(BatchNolb.Text, DateOfIssuelb.Text, ItemNamelb.Text, Colorlb.Text, "Grade1", 1, 100);
                    dt.Rows.Add(BatchNolb.Text, DateOfIssuelb.Text, ItemNamelb.Text, Colorlb.Text, "Grade2", 2, 200);
                    dt.Rows.Add(BatchNolb.Text, DateOfIssuelb.Text, ItemNamelb.Text, Colorlb.Text, "Grade3", 3, 300);
                    
                    for (var i = dt.Rows.Count; i < 7; i++)
                    {
                        emptyrow++;
                    }
    
                    Repeater rep = e.Item.FindControl("Repeater2") as Repeater;
                    rep.DataSource = dt;
                    rep.DataBind();
                }
            }
    
    protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
    
                    Label l2 = e.Item.FindControl("Label2") as Label;
                    Label l3 = e.Item.FindControl("Label3") as Label;
                    try
                    {
                        pscTotal += Convert.ToInt32(l2.Text);
                        amountTotal += Convert.ToInt32(l3.Text);
                    }
                    catch
                    {
                       
                    }
                }
                if (e.Item.ItemType == ListItemType.Footer)
                {
                    if (emptyrow > 0)
                    {
                        HtmlTableRow a = (HtmlTableRow)e.Item.FindControl("hiddenrow");
                        a.Visible = true;
                        a.Height = 20 * emptyrow + "px";
                    }
                    emptyrow = 0;
                    Label l4 = e.Item.FindControl("Label4") as Label;
                    Label l5 = e.Item.FindControl("Label5") as Label;
                    l4.Text = pscTotal.ToString();
                    l5.Text = amountTotal.ToString();
                }
            }


    And the result is:

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 6, 2017 7:45 AM