This is a migrated thread and some comments may be shown as answers.

Removing Repeating Cell Values

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 10 Apr 2013, 04:56 PM
<telerik:GridTemplateColumn Datafield="customer_cd" HeaderStyle-Width="20%"
    HeaderText="Customer" ItemStyle-HorizontalAlign="Center" SortExpression="end_dt"
    ItemStyle-VerticalAlign="Middle" UniqueName="customer_cd">
    <ItemTemplate>
        <table>
            <colgroup>
                <col />
            </colgroup>
            <tr>
                <td>
                    <asp:HyperLink ID="hlCustomerCd" runat="server" ImageUrl='<%# string.Format("icons/{0}.gif",Eval("customer_cd")) %>' NavigateUrl='<%# string.Format("customer.aspx?org_cd={0}&cust_id={1}", org_cd, Eval("customer_id"))  %>'
                        Text='<%# Eval("customer_nm").ToString() %>' />
                    <br />
                    <asp:Label ID="lblCustomerCd" runat="server" Text='<%# Eval("customer_nm").ToString() %>' Font-Size="X-Small" />
                    <br />
                    <asp:HyperLink ID="hlAgreementNo" runat="server" NavigateUrl=' <%# string.Format("agreement.aspx?org_cd={0}&cust_id={1}&agmt_id={2}", org_cd, Eval("customer_id"), Eval("agreement_id"))%>' Text='<%# "Agreement:" + Eval("customer_purchase_order_no") %>' ForeColor="#2dabc1" />
                </td>
            </tr>
        </table>
    </ItemTemplate>
</telerik:GridTemplateColumn>

protected void rgSite_PreRender(object sender, EventArgs e)
{
    //The Row Index is the Row above the bottom row, walk up the Grid
    for (int rowIndex = rgSite.Items.Count - 2; rowIndex >= 0; rowIndex += -1)
    {
        //The Current Row is the row index
        GridDataItem row = rgSite.Items[rowIndex];
        //The Previous Row is one below it
        GridDataItem previousRow = rgSite.Items[rowIndex + 1];
        //Grab the ItemTemplate Text values from the Hyperlink of the current and previous row and compare them.
        if ((row["customer_cd"].FindControl("hlCustomerCd") as HyperLink).Text == (previousRow["customer_cd"].FindControl("hlCustomerCd") as HyperLink).Text)
        {
            //The Top Row Absorbs the previous Rowspan
            row["customer_cd"].RowSpan = previousRow["customer_cd"].RowSpan < 2 ? 2 : previousRow["customer_cd"].RowSpan + 1;
            //The previous row then goes away.
            previousRow["customer_cd"].Visible = false;
        }
    }
}

This is sort of a minor adjustment to the solution given in another forum to allow for the same thing in a Grid Template Column. 

1 Answer, 1 is accepted

Sort by
0
MasterChiefMasterChef
Top achievements
Rank 2
answered on 10 Apr 2013, 08:18 PM
Hi Justin,

What exactly are the 'repeating cell values' ? Are you referring to the Units, Diff. Factor, and Remarks? If these are the same for each item in an AGREEMENT then you could consider creating a Hierarchical Grid and bounding these repeating cells to each AGREEMENT itself. You could achieve this functionality by following this demo: http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx

Hopefully this helps,
Master Chief
Tags
Grid
Asked by
Justin
Top achievements
Rank 1
Answers by
MasterChiefMasterChef
Top achievements
Rank 2
Share this question
or