I have a simple RadGrid:
The columns and rows are bound to a table in a database; yet some of the columns do not contain any data (that is, all the entries in that column are NULL). I need to hide those columns that do not contain any data after the grid has been filled. I tried the following handler for the OnDataBound event:
This fails, however, because rgHeaderKey.Columns.Count is always 0, even after the data have been bound (which I find a bit strange). I realise this might be because the columns are automatically generated: however, I need it this way because I do not know the names of the columns in advance.
Any help would be very much appreciated.
<
telerik:RadGrid
ID
=
"rgHeaderKey"
runat
=
"server"
>
<
HeaderStyle
Font-Bold
=
"true"
/>
<
MasterTableView
HeaderStyle-HorizontalAlign
=
"Center"
HeaderStyle-Font-Bold
=
"true"
/>
</
telerik:RadGrid
>
The columns and rows are bound to a table in a database; yet some of the columns do not contain any data (that is, all the entries in that column are NULL). I need to hide those columns that do not contain any data after the grid has been filled. I tried the following handler for the OnDataBound event:
protected
void
GridHeaderKeyDataBound(
object
sender, EventArgs e)
{
// after data-binding, hide any columns that have no entries
for
(
int
i = 0; i < rgHeaderKey.Columns.Count; i++)
{
// check the entry in the first row
GridColumn col = rgHeaderKey.Columns[i];
if
(String.IsNullOrEmpty(rgHeaderKey.Items[0][col].Text)) col.Display =
false
;
}
}
This fails, however, because rgHeaderKey.Columns.Count is always 0, even after the data have been bound (which I find a bit strange). I realise this might be because the columns are automatically generated: however, I need it this way because I do not know the names of the columns in advance.
Any help would be very much appreciated.