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

Hide duplicate values in RadGrid column

7 Answers 292 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hanoch Faran
Top achievements
Rank 1
Hanoch Faran asked on 15 Jan 2009, 11:50 AM
I want to bind the grid to query results.
A person might appear several times and I want to sort the results using person ID.
Is there a way to hide duplicate values (e.g. ID, First name, Last name etc.) in the grid?

I wish there was a property like 'HideDuplicates'  in MS Access.

7 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 15 Jan 2009, 11:59 AM
Hello Hanoch,

You can implement this functionality on database level. For example:

SELECT DISTINCT ID, FirstName, LastName FROM YourTable

Let us know if you need more information.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Hanoch Faran
Top achievements
Rank 1
answered on 15 Jan 2009, 12:46 PM
Thanks Daniel

But a DISTINCT won't help here since some columns will be different (such as order id, order date etc.)
I want the grid to look like in this example:
Man ID | Name    | Order ID | Order Date | Total Price
=========================================
|  101   | Joe K.   | 1001       | 1/1/09         | 50$  
|           |              | 1004       | 3/1/09         | 120$  
|  103   | Tim B.   | 1002       | 1/1/09         | 70$  
|           |              | 1003       | 4/1/09         | 100$  

As I said, a new GridBoundColumn's property called HideDuplicates will be nice.

Meanwhile, I managed to get what I wanted with this method:

1) I wrote this generic function:
        private Hashtable hashLastValues = new Hashtable();
...
        protected string myHideDuplicate(object oField,string FldName)
        {
            string CurValue = oField.ToString();
            if (hashLastValues.ContainsKey(FldName))
                if ((string)hashLastValues[FldName]==CurValue)
                    CurValue = "";
                else
                    hashLastValues[FldName]=CurValue;
            else
                hashLastValues.Add(FldName, CurValue);

            return CurValue;
        }

2) I defined columns in the grid like this:
            <telerik:GridTemplateColumn DataField="ManFamily" HeaderText="Last Name">
            <ItemTemplate>
            <asp:Label runat="server" Text='<%# myHideDuplicate(Eval("ManFamily"),"ManFamily") %>'></asp:Label>
            </ItemTemplate>
            </telerik:GridTemplateColumn>

And it's working fine now.
0
IT
Top achievements
Rank 1
answered on 21 Jan 2010, 04:09 PM
Hi here

I've also been looking into doing the same thing

but no success

how does your method work ?
0
Princy
Top achievements
Rank 1
answered on 22 Jan 2010, 05:40 AM
Hello Brian,

You can merge the cells having duplicate values using the following code:
c#:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
       for (int rowIndex = RadGrid1.Items.Count - 2; rowIndex >= 0; rowIndex--) 
        { 
            GridDataItem row = RadGrid1.Items[rowIndex]; 
            GridDataItem previousRow = RadGrid1.Items[rowIndex + 1]; 
 
            for (int i = 0; i < row.Cells.Count; i++) 
            { 
                if (row.Cells[i].Text == previousRow.Cells[i].Text) 
                { 
                    row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 : previousRow.Cells[i].RowSpan + 1; 
                    previousRow.Cells[i].Visible = false
                } 
            } 
 
        } 
   } 

Hope this helps..
Princy.
0
Karthikeyan
Top achievements
Rank 1
answered on 19 Sep 2011, 11:24 AM
Hi Princy,

Will it applicable for Silverlight RADGRIDVIEW also.
If yes, Can you please tell me how we can call this method/changes?

Please guide me to do.

Thanks,
Karthikeyan Manickam.
0
Mark
Top achievements
Rank 1
answered on 24 Oct 2018, 10:23 PM
This solution is perfect, worked for me. Thanks Hanoch Faran.
0
Maysam
Top achievements
Rank 1
answered on 22 Apr 2019, 06:14 PM
protected void gridDocShow_OnPreRender(object sender, EventArgs e)
        {
            gridDocShow.Rebind();
            for (int rowIndex = 0; rowIndex < gridDocShow.Items.Count - 1; rowIndex++)
            {
                if (gridDocShow.Items[rowIndex].KeyValues == gridDocShow.Items[rowIndex + 1].KeyValues)
                {
                    gridDocShow.Items[rowIndex].Visible = false;
                }
            }
        }
Tags
Grid
Asked by
Hanoch Faran
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Hanoch Faran
Top achievements
Rank 1
IT
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Karthikeyan
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Maysam
Top achievements
Rank 1
Share this question
or