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

Hiding the value of a cell without collapsing the column

2 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adrian
Top achievements
Rank 1
Adrian asked on 02 Jun 2014, 04:58 AM
I have a RadGrid on my page displaying a list of search results from my database. Some of these results have associated files which I provide a download link for, and some don't.

For the results that don't have an associated file I want to hide the link in that row only. I can do that, I've found, using this code in the ItemDataBound event:

if (e.Item is Telerik.Web.UI.GridDataItem)
{
    if (!((bool)((DataRowView)e.Item.DataItem).Row["IsElectronic"]))
    {
        ((Telerik.Web.UI.GridDataItem)e.Item)["colDownload"].Visible = false;
    }
}

The problem is that by setting the GridDataItem's Visible property I'm effectively collapsing that column for that row, moving everything out of alignment with the grid headers. Instead, I'd like to do something to empty the contents of the cell, or change just that cell to a different column type, or something similar?

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 02 Jun 2014, 05:34 AM
Hi Adrian,

You can set its Text property to empty string instead of setting visible property.

C#:
((Telerik.Web.UI.GridDataItem)e.Item)["colDownload"].Text = string.Empty;

Thanks,
Shinu
0
Adrian
Top achievements
Rank 1
answered on 03 Jun 2014, 04:57 AM
Hi Shinu,

Thanks for that. That worked a treat.
Tags
Grid
Asked by
Adrian
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Adrian
Top achievements
Rank 1
Share this question
or