How do I show gridlines even if cell is empty. I want to make this fix in all places. Is there any general code for this issue?
I have the radgrid structure like below
<
netcweb:NCRadGrid runat="server" ID="ActivityGrid"
OnNeedDataSource="ActivityGrid_NeedDataSource"
OnItemCreated="ActivityGrid_OnItemCreated"
PageSize="10" AllowPaging="true" SkinID="ActivityList"
OnPageSizeChanged="ActivityGrid_PageSizeChanged" OnPreRender="ActivityGrid_PreRender">
<PagerStyle AlwaysVisible="true" />
<ClientSettings AllowGroupExpandCollapse="true" />
<GroupingSettings />
<MasterTableView AutoGenerateColumns="false" GroupLoadMode="client">
<Columns>
<telerik:GridTemplateColumn UniqueName="1" HeaderText="My courses student page">
<ItemTemplate>
<netcweb:PlaceHolderControl runat="server" ID="column1PlaceHolder">
</netcweb:PlaceHolderControl>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="2" HeaderText="StudentCourseListStatusHeader">
<ItemTemplate>
<netcweb:PlaceHolderControl runat="server" ID="column2PlaceHolder">
</netcweb:PlaceHolderControl>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="3" HeaderText="StudentCourseListDateHeader">
<ItemTemplate>
<netcweb:PlaceHolderControl runat="server" ID="column3PlaceHolder">
</netcweb:PlaceHolderControl>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="4" HeaderText="">
<HeaderTemplate>
<netcweb:ImageCheckBoxControl runat="server" ID="DetailedListCheckBox"
OnCheckedChanged="DetailedListCheckBox_OnCheckedChanged" AutoPostBack="true"
SkinID="DetailedView" />
</HeaderTemplate>
<ItemTemplate>
<netcweb:PlaceHolderControl runat="server" ID="column4PlaceHolder">
</netcweb:PlaceHolderControl>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</netcweb:NCRadGrid>
I tried the below code. All the values reside that grid was returns empty.
protected void ActivityGrid_PreRender(object sender, EventArgs e)
{
foreach (GridDataItem dataItem in ActivityGrid.MasterTableView.DetailTables[0].Items)
{
foreach (GridColumn col in ActivityGrid.MasterTableView.DetailTables[0].Columns)
{
if (dataItem[col.UniqueName].Text == string.Empty)
dataItem[col.UniqueName].Text =
" ";
}
}
}
13 Answers, 1 is accepted
Please add " " at the end of the item templates. This will make the cells non-empty in all cases.
http://www.telerik.com/community/forums/aspnet-ajax/grid/border-not-displayed-if-cell-is-empty-in-internet-explorer.aspx
Greetings,
Dimo
the Telerik team
Thanks. Its working. But i wanted to make this for all radgrid in my projects. I have plenty of radgrids in my projects. Each radgrid I couldn'd add the " " manually. Is it possible to write the function in one place?
You can inherit the RadGrid control and always execute an ItemDataBound or PreRender handler to add the string where needed. The handler can be attached in the constructor of the custom class inheriting from RadGrid.
Kind regards,
Dimo
the Telerik team
I have inherited the RadGrid control and it executes both ItemDatabound/PreRender handler.
If I add the string, all the cell value left empty. I tried the below code
protected override void OnPreRender(EventArgs e)
{
ControlHelper.RegisterScriptFile("~/App/script/NCRadGrid.js");
foreach (GridItem item in MasterTableView.Items)
{
foreach (TableCell cell in item.Cells)
{
cell.Text += " ";
}
}
For template cells you need to add the string as a literal control. Setting the Text property to a table cell clears its controls collection and vice versa - adding a control to a table cell clears its Text value.
All the best,
Dimo
the Telerik team
Is there any common place to set this? As per your reply I inherited the radcontrol.
Is it possible to add a " " string in common place. Because I couldn't add the " " string manually for all the column in the Grid. I have more than 50 grids in my project. Also I like to make this functionality in one place.
I am looking forward to hear from you.
Please review carefully the attached demo.
Dimo
the Telerik team
I reviewed your attached demo. I think that is not my need. I want to make this functionality in common place, not for one grid.
I need this for all grids. After binding the grid, I should check the cell value, If it is empty I need to append the string " ".
The value returns empty for me as I am using ItemTemplate. If it is a bound column, it returns a value.
I just want to know, how to get the cell value after binding the grid on prerender event / some other event.
In few grids I have placeholder and in few grids having label or literal controls. Hence I need to get the value after binding the grid. My assumptions is the grid would be in table format after binding the grid.
Could you please help me out from this issue?
Please feel free to ask me, if you need more description.
The demonstrated functionality is not for one grid - it will work for all controls, which use the MyGrid class inheriting from Telerik.Web.UI.RadGrid. I believe I have provided all the information that you need.
Dimo
the Telerik team
Yes, you are right. Sorry I dint notice the MyGrid.cs.
Thanks a lot. Code is working.
<
script
type
=
"text/javascript"
>
$(document).ready(function () {
$(".RadGrid .rgRow TD:empty").append(' ');
});
</
script
>