disapearing gridlines in gridview

G

Guest

Hello Everyone,

I have a gridview. I am using template columns inside the gridview.
When I display the gridview on the web page and if there is no value in a
particular cell, gridline disappaers around that cell.I want the grid lines
to appear all the time even if the cell is empty. Can anyone tell me what am
I doing wrong. Below is my gridview. I am showing only one template column. I
have around 14 template column in the gridview.


<asp:GridView ID="dgAgentActivity" runat="server"
AutoGenerateColumns="false" CellPadding="0" CellSpacing="1"
BackColor="AliceBlue" OnRowCreated="dgAgentActivity_RowCreated"
ShowFooter="true" >
<Columns>

<asp:templatefield headertext="SwitchTime" >

<itemtemplate>
<%#Eval("SwitchTime")%>
</itemtemplate>
<footertemplate>
<asp:label id="SwitchTime" runat="server"/>
</footertemplate>
</asp:templatefield>
<columns>

Thanks.
 
R

Ray Costanzo

That's how the browser renders a <td> that has no content. Often, an nbsp;
is put in such a TD to get it to render the way you want it. So, depending
on how you get your data or how you want to do it, you may want to consider
replacing empty values with &nbsp;.

Notice what happens if you add this:
<style type="text/css">
table.Vinki td { height: 3em; border: 1px solid #000000; }
</style>

And give your GridView a CssClass="Vinki" property. Load this in IE and
then in Firefox. It's all in how each browser decides to deal with things,
and it's a pita!

Ray at work
 
G

Guest

Hi Ray,

Thanks for replying. Do you know any way or if you have any example, I can
replace the empty cells with in gridview.

Thanks.
 
G

Guest

Hi Ray,

I tried doing this

for (int i = 0; i <= 17; i++)
{
if
(((DataBoundLiteralControl)e.Row.Cells[2].Controls[0]).Text.Trim() ==
string.Empty)

((DataBoundLiteralControl)e.Row.Cells[2].Controls[0]).Text = "&nbsp";

}

but this didn't work. I have 18 template columns so I want to do it in a
loop. Is there any other way I can do it.
 
R

Ray Costanzo

Yeah, I'd say your best bet is to go for a solution that does not involve
modifying your data.

There is a CSS attribute for the table element called empty-cells, but as is
typical, IE doesn't support it. But, if you set border-collapse to collapse
at the table level, IE will show the border on the empty cells. Hopefully
this will fit with the look you're going for.

<style type="text/css">
table.test { border-collapse: collapse; }
table.test td { border: 1px solid #000000; empty-cells: show; width: 33%}
</style>
<table class="test">
<tr>
<td>content</td>
<td></td>
<td>content</td>
</tr>
</table>

Ray at work


Vinki said:
Hi Ray,

I tried doing this

for (int i = 0; i <= 17; i++)
{
if
(((DataBoundLiteralControl)e.Row.Cells[2].Controls[0]).Text.Trim() ==
string.Empty)

((DataBoundLiteralControl)e.Row.Cells[2].Controls[0]).Text = "&nbsp";

}

but this didn't work. I have 18 template columns so I want to do it in a
loop. Is there any other way I can do it.

Ray Costanzo said:
That's how the browser renders a <td> that has no content. Often, an
nbsp;
is put in such a TD to get it to render the way you want it. So,
depending
on how you get your data or how you want to do it, you may want to
consider
replacing empty values with .

Notice what happens if you add this:
<style type="text/css">
table.Vinki td { height: 3em; border: 1px solid #000000; }
</style>

And give your GridView a CssClass="Vinki" property. Load this in IE and
then in Firefox. It's all in how each browser decides to deal with
things,
and it's a pita!

Ray at work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top