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

RadGrid - show gridlines even if cell is empty.

13 Answers 391 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Priya B
Top achievements
Rank 1
Priya B asked on 18 Jun 2010, 10:47 AM
Hi

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 =

"&nbsp;";

 

}

}

 

}

 


 

 

13 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 18 Jun 2010, 11:13 AM
Hi Priya,

Please add "&nbsp;" 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Priya B
Top achievements
Rank 1
answered on 18 Jun 2010, 11:25 AM
Hi Dimo,

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 "&nbsp;" manually. Is it possible to write the function in one place?



0
Dimo
Telerik team
answered on 18 Jun 2010, 12:44 PM
Hi Priya,

You can inherit the RadGrid control and always execute an ItemDataBound or PreRender handler to add the &nbsp; string where needed. The handler can be attached in the constructor of the custom class inheriting from RadGrid.

Kind regards,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Priya B
Top achievements
Rank 1
answered on 18 Jun 2010, 12:49 PM
Could you please provide some sample?
0
Priya B
Top achievements
Rank 1
answered on 21 Jun 2010, 07:13 AM

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 += "&nbsp;";
                }
            }

0
Dimo
Telerik team
answered on 21 Jun 2010, 10:06 AM
Hi Priya,

For template cells you need to add the &nbsp; 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Priya B
Top achievements
Rank 1
answered on 21 Jun 2010, 10:12 AM
Hi Dimo,

Is there any common place to set this? As per your reply I inherited the radcontrol.

Is it possible to add a "&nbsp;" string in common place. Because I couldn't add the "&nbsp;" 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.
0
Accepted
Dimo
Telerik team
answered on 21 Jun 2010, 11:03 AM
Hello Priya,

Please review carefully the attached demo.

Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Priya B
Top achievements
Rank 1
answered on 21 Jun 2010, 11:26 AM
Hi Dimo,

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 "&nbsp;". 
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.

 

 

0
Dimo
Telerik team
answered on 21 Jun 2010, 12:00 PM
Priya,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Priya B
Top achievements
Rank 1
answered on 22 Jun 2010, 07:49 AM
Hi Dimo,

Yes, you are right. Sorry I dint notice the MyGrid.cs.

Thanks a lot. Code is working.
0
Luke
Top achievements
Rank 2
answered on 21 Nov 2012, 12:02 AM
You could also solve this problem with some jQuery:

  <script type="text/javascript">
     $(document).ready(function () {
        $(".RadGrid .rgRow TD:empty").append(' ');
     });
  </script>
0
Luke
Top achievements
Rank 2
answered on 21 Nov 2012, 12:03 AM
 
Tags
Grid
Asked by
Priya B
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Priya B
Top achievements
Rank 1
Luke
Top achievements
Rank 2
Share this question
or