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

blank column in grid

16 Answers 640 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ChrisWalker
Top achievements
Rank 1
ChrisWalker asked on 02 Jun 2008, 08:56 PM

I have found that for the telerik provided skins that produce a border around the cell, for example Inox which just has a horizontal border, I must change blank values to   to see that border when the value is blank.

Is there a better way to handle this situation where I must change the value in itemdatabound to get the border to show?

ex:

if

(dataView["CodeDesc"].ToString().Trim().Length == 0)

{

dataitem[

"CodeDesc"].Text = "&nbsp";

}

16 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Jun 2008, 05:32 AM
Hi,

Can you try with the following code snippet?

CS:
protected void RadGrid2_PreRender(object sender, EventArgs e)  
    {  
        foreach (GridDataItem dataItem in RadGrid2.Items)  
        {  
            foreach (GridColumn col in RadGrid2.Columns)  
            {  
                if (dataItem[col.UniqueName].Text == string.Empty)  
                    dataItem[col.UniqueName].Text += "&nbsp";    
   
            }  
        }  
    }  


Thanks
Princy.
0
ChrisWalker
Top achievements
Rank 1
answered on 03 Jun 2008, 01:01 PM

Princy,
Thanks for the reply. Your suggestion would simply move what I already have in itemdatabound to prerender althoough it would do this in one step rather than for each item.

What I was looking for was a way that this could be done without any code on my part given the fact that Telerik's design point  seems to be "create a grid without any coding on your part" which I really like. I just thought I was missing a tag attribute or somethng clever that Telerik has alrady done for this case.

I guess they have not so I will keep my itemdatabound handler code as is.

Thanks again.

0
Dimo
Telerik team
answered on 04 Jun 2008, 07:33 AM
Hi Chris,

The latest versions of RadGrid for ASP.NET and RadGrid for ASP.NET AJAX add " " strings to empty data cells automatically. Are you using some old version of the control?

Greetings,
Dimo
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
ChrisWalker
Top achievements
Rank 1
answered on 04 Jun 2008, 01:50 PM

Hello Dimo,
I am using the 2008.1.515.35 of Telerik.Web.UI.dll. Further investigation of my data query revealed that the column in question returned a ' ' (single blank) and not a NULL as I think you were expecting.

If I changed the query in the select from simply returning the column to

case RTRIM(A.CODEDESC) WHEN '' then NULL ELSE A.CODEDESC END as CODEDESC

the ' ' will now be returned as a NULL and your code works as described in your post.

I have found that I needed to add the RTRIM SQL function to handle blank columns with a length more than 1, for example '    '.


0
Tommy
Top achievements
Rank 1
answered on 20 Jun 2008, 08:08 AM
Hi,

I have the same problem. I'm using the IE7 and the latest version of the controls. When the cell of the grid has no value, it shows no border around the cell.
I tried the workaround with the &nbsp, but I have templates in my grid. If I try the &nbsp workaround all cells are blank.

Do you have another solutions for this?

Thanks
Tommy
0
Dimo
Telerik team
answered on 20 Jun 2008, 08:28 AM
Hello Tommy,

Are you sure that you are appending the   string to the template cells? Maybe you are replacing the cell content and that is why the cells are blank,

When using templates, the easiest way is to simply add unconditionally the   string at the end of the template.

Regards,
Dimo
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Tommy
Top achievements
Rank 1
answered on 20 Jun 2008, 08:57 AM
Yep, that was it. It works.

Thanks Dimo.
0
Tommy
Top achievements
Rank 1
answered on 06 Aug 2008, 10:55 AM
I have an additional question to this topic.

When I add a "&nbsp" to my cell and I export it to PDF, the "&nbsp" string is in each column of the PDF. When I export it to word or to excel I don't have the string in it.

Can you help me to solve this problem. Thank you. 
0
Daniel
Telerik team
answered on 06 Aug 2008, 02:11 PM
Hello Tommy,

Excel interprets this character as html code unlike in PDF where it is shown like plain text. You can avoid this using a simple flag, indicating that you are currently exporting to PDF file. This will help you add &nbsp only when applicable, i.e.:

bool isPdfExport = false
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if (e.CommandName == RadGrid.ExportToPdfCommandName) 
    { 
        isPdfExport = true
    } 

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Tommy
Top achievements
Rank 1
answered on 07 Aug 2008, 07:31 AM
Hello Daniel,

what I mean is, I add the string "&nbsp" to my cells to get a border around each cell where I have a database NULL value in it.
Currently when I'm exporting the grid data to excel or word the "&nbsp" is not shown, only when I'm exporting to PDF.
What I want is, that I don't see the "&nbsp" string in the PDF.

Thanks
Thomas
0
Daniel
Telerik team
answered on 08 Aug 2008, 05:04 PM
Hello Thomas,

The idea of the code shown below is to use a flag to indicate when you are exporting PDF. This is needed in order to prevent the useless "&nbsp" to be put into your PDF document. Instead the &nbsp workaround you can set RadGrid1.GridLines = GridLines.Both; or GridLines="Both" to explicitely show the grid lines.

Please try the suggested code and let us know if you need further assistance.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Tommy
Top achievements
Rank 1
answered on 03 Sep 2008, 11:04 AM
Hi Daniel,

the solutions with RadGrid1.GridLines = GridLines.Both; or GridLines="Both" doesn't work.
When I remove "&nbsp" and set the Gridlines to both, there are still no gridlines.

Any Idea?

Thomas
0
Daniel
Telerik team
answered on 05 Sep 2008, 12:18 PM
Hello Tommy,

For your convenience I attached a sample website illustrating the mentioned approach.

Greetings,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Justin
Top achievements
Rank 1
answered on 21 Apr 2009, 02:12 AM
Hi,
I am using version 2008.3.1314.20 and using the above suggested code in the prerender event in order to add a nbsp ( ) to empty column fields so the column grid line is displayed in IE. It works fine for the first page load, but for some reason on the postback of an outside control (that does nothing more than do the postback), the column grid lines are missing again for the empty fields although when I debug the prerender event the nbsp exist in all empty fields.
Any ideas? Thanks
0
Sebastian
Telerik team
answered on 23 Apr 2009, 11:34 AM
Hi Justin,

You can use the PreRender event of the grid to ensure that the   symbols will be added to the cells on each postback. Another solution would be to intercept the ItemDataBound event of the grid and inject the empty symbol there:

http://www.telerik.com/community/forums/aspnet-ajax/grid/border-not-displayed-if-cell-is-empty-in-internet-explorer.aspx

and call the Rebind() method of the grid on postbacks from other controls on the page. Thus the ItemDataBound event will be raised and the value will be inserted as expected.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Justin
Top achievements
Rank 1
answered on 28 Apr 2009, 03:06 AM

Hi Sebastian,

Thanks for the alternative solution. But my problem was that i wasn't calling the Rebind() method from the other controls as you suggested and that sorted my problem.
Best regards
Justin

Tags
Grid
Asked by
ChrisWalker
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
ChrisWalker
Top achievements
Rank 1
Dimo
Telerik team
Tommy
Top achievements
Rank 1
Daniel
Telerik team
Justin
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or