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

Column borders invisible when there are empty cells in rad grid

1 Answer 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Biswajit
Top achievements
Rank 1
Biswajit asked on 22 Mar 2012, 05:06 AM
I am showing my search results in a rad grid. Rad grid is inside a panel. Whenever there are empty cells, column lines are becoming invisible.
I used the below code in prerender event of the grid, still columns lines become invisible for empty cells.
This scenario happens sometimes on grid refresh.

protected void rgMyGrid_PreRender(object sender, EventArgs e)
        {
            try
            {
 
                foreach (GridDataItem item in rgMyGrid.MasterTableView.Items)
                {
                    if (item is GridDataItem)
                    {
                        foreach (GridColumn col in rgMyGrid.Columns)
                        {
                            //Add space to the cell that has null or empty value
                            if (!col.ColumnType.Equals("GridTemplateColumn"))
                            {
                                if (string.IsNullOrEmpty(item[col.UniqueName].Text.Trim())
                                    || item[col.UniqueName].Text.Equals(" "))
                                {
                                    item[col.UniqueName].Text = " ";
                                }
                            }
                            else
                            {
                                #region AllowSpaceInCols
                                switch (col.UniqueName)
                                {
                                    case "lblColumn1":
                                        Label lblColumn1= item.FindControl("lblColumn1") as Label;
                                        if (lblColumn1.Text.Trim().Equals(String.Empty)
                                            || lblColumn1.Text.Trim().Equals(" "))
                                        {
                                            lblColumn1.Text = " ";
                                        }
                                        break;
 
                                    case "Column2":
                                        Label lblColumn2 = item.FindControl("lblColumn2") as Label;
                                        if (lblColumn2 .Text.Trim().Equals(String.Empty)
                                            || lblColumn2 .Text.Trim().Equals(" "))
                                        {
                                            lblColumn2 .Text = " ";
                                        }
                                        break;
 
                                    default:
                                        break;
                                }
                                #endregion
                            }
                        }
                    }
 
                }
            }
            catch (Exception ex)
            {
 
            }
        }

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Mar 2012, 08:22 AM
Hi Biswajit,

This issue is a limitation of earlier version of Internet Explorer. RadGrid inserts   strings to all its data cells by default, except for GridTemplateColumn cells. When using template columns, you can add a    instead of  “ “  if the cell is empty. Here is the code which I tried.
C#:
Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
    For Each dataItem As GridDataItem In RadGrid1.Items
        Dim lb As Label = DirectCast(dataItem.FindControl("Label2"), Label)
        If lb.Text = String.Empty Then
            lb.Text += "&nbsp"
        End If
    Next
End Sub

Thanks,
-Shinu.
Tags
Grid
Asked by
Biswajit
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or