473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

hide these null values in datagrid

Hey Group,

I may just be suffering brain fade but I have searched around and not
been able to find a solution. My difficulty: I have a datagrid that
shows name, address, tel, fax and toll free number. I would like to
hide the empty values. For instance; no fax = no fax number row, no
toll free = no TF row. I'm sure it must be something I am overlooking
or not thinking through.

All I can give back is my gratitude.....

<asp:datagrid AllowCustomPaging="true" AllowPaging="true"
AutoGenerateColumns="false" DataSource="<%# listings.DefaultView %>"
id="dgListings" PagerStyle-Mode="NextPrev" PageSize="<%#
listings.PageSize %>" runat="server"
OnPageIndexChanged="listings.OnDataGridPageIndexCh anged"
virtualitemcount="<%# listings.RecordCount %>">
<Columns>
<asp:BoundColumn DataField="Business Category"
HeaderText="Business Category"
ReadOnly="true"
Visible="False"/>
<asp:TemplateColumn HeaderText="Business Information">
<ItemTemplate>
<table border="0">
<tr>
<td align="right"><b>Name:</b></td>
<td<%# DataBinder.Eval(Container.DataItem, "Business
Name") %</td>
</tr>
<tr>
<td align="right"><b>Address:</b></td>
<td<%# DataBinder.Eval(Container.DataItem, "Address")
%</td>
</tr>
<tr>
<td align="right"></td>
<td<%# DataBinder.Eval(Container.DataItem, "Town") %>,
<%# DataBinder.Eval(Container.DataItem, "State") %<%#
DataBinder.Eval(Container.DataItem, "ZipCode") %</td>
</tr>
<tr>
<td align="right"><b>Telephone:</b></td>
<td<%# DataBinder.Eval(Container.DataItem, "WorkPhone")
%</td>
</tr>
<tr>
<td align="right"><b>Fax:</b</td>
<td<%# DataBinder.Eval(Container.DataItem, "FaxNumber")
%</td>
</tr>
<tr>
<td aligh="right"><b>Toll Free:</b></td>
<td<%# DataBinder.Eval(Container.DataItem, "TollFree")
%</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn</Columns>
</asp:datagrid>

************************************************** *****
they have the internet on computers now?!?
************************************************** *****

Aug 23 '06 #1
1 2346
You can wrap the entire production up in a method, so something like

<asp:TemplateColumn HeaderText="Business Information">
<ItemTemplate>
<table border="0">
<%# GetTableRow(Container.DataItem) %>
<tr>
<td align="right"><b>Address:</b></td>
<td<%# DataBinder.Eval(Container.DataItem, "Address")%</td>
</tr>
</table>
...

protected string GetTableRow(object o)
{
string s = Eval(Container.DataItem, "Business Name");
if(s.IsNullOrEmpty()
return "";
else
return string.Format("<tr><td a lign='right'>
<b>Name:</b></td><td>{0}</td></tr>", s);
}

This is typed into my news reader so there are probably compiler errors,
but the idea is that you can provide a method, have the template call
the method passing the current data item. The method returns a string
from that containing the data you need to display. The method can then
call Eval on the dataitem passed in,

desmoduck wrote:
Hey Group,

I may just be suffering brain fade but I have searched around and not
been able to find a solution. My difficulty: I have a datagrid that
shows name, address, tel, fax and toll free number. I would like to
hide the empty values. For instance; no fax = no fax number row, no
toll free = no TF row. I'm sure it must be something I am overlooking
or not thinking through.

All I can give back is my gratitude.....

<asp:datagrid AllowCustomPaging="true" AllowPaging="true"
AutoGenerateColumns="false" DataSource="<%# listings.DefaultView %>"
id="dgListings" PagerStyle-Mode="NextPrev" PageSize="<%#
listings.PageSize %>" runat="server"
OnPageIndexChanged="listings.OnDataGridPageIndexCh anged"
virtualitemcount="<%# listings.RecordCount %>">
<Columns>
<asp:BoundColumn DataField="Business Category"
HeaderText="Business Category"
ReadOnly="true"
Visible="False"/>
<asp:TemplateColumn HeaderText="Business Information">
<ItemTemplate>
<table border="0">
<tr>
<td align="right"><b>Name:</b></td>
<td<%# DataBinder.Eval(Container.DataItem, "Business
Name") %</td>
</tr>
<tr>
<td align="right"><b>Address:</b></td>
<td<%# DataBinder.Eval(Container.DataItem, "Address")
%</td>
</tr>
<tr>
<td align="right"></td>
<td<%# DataBinder.Eval(Container.DataItem, "Town") %>,
<%# DataBinder.Eval(Container.DataItem, "State") %<%#
DataBinder.Eval(Container.DataItem, "ZipCode") %</td>
</tr>
<tr>
<td align="right"><b>Telephone:</b></td>
<td<%# DataBinder.Eval(Container.DataItem, "WorkPhone")
%</td>
</tr>
<tr>
<td align="right"><b>Fax:</b</td>
<td<%# DataBinder.Eval(Container.DataItem, "FaxNumber")
%</td>
</tr>
<tr>
<td aligh="right"><b>Toll Free:</b></td>
<td<%# DataBinder.Eval(Container.DataItem, "TollFree")
%</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn</Columns>
</asp:datagrid>

************************************************** *****
they have the internet on computers now?!?
************************************************** *****
Aug 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Maurice Mertens | last post by:
Hi all, I'm trying to hide the value 'null' in a bound datagrid but somehow it doesn't work. I set the .Nulltext property to a certain value: ... ... TblStyle.Add(New...
10
by: oLE | last post by:
I would like to add some javascript to show/hide a certain row of a table. The first row of the table contain the hyperlink that calls the javascript the second row is the one i want to show/hide...
4
by: jez123456 | last post by:
Not sure if I'm in the right thread but here goes. I have an ASP.Net web page with a datagrid. The code behind is C#. If the datagrid has no records the datagrid header section is still shown....
6
by: Das | last post by:
Hi everyone, I'm using datagrid control to display the data. I want to hide column to be displayed into the data grid. I'm using the code as given below: Method given below is used to bind the...
4
by: Tim | last post by:
Hi, I am trying to hide the datagrid row header (the left most column that has the 'select' triangle in it which moves with the selected row). It seems to be fairly simple;...
2
by: Kel Good | last post by:
Hello, I am binding a custom IList object to a DataList that I am using for a web menu. The items in the custom IList have properties that allow me to dynamically define how my menu behaves. My...
4
by: Wayne Wengert | last post by:
I have a datagrid bound to dataset where some entries are null. In that grid I am defining a column as Boolean (see code below) and I get the expected checkbox which is checked or unchecked when...
5
by: Shane Story | last post by:
I have a dataset with two tables. I make data view of each table, connect the parent table to one data grid and the child table to the other datagrid, with a row filter, that gets set when a...
2
by: harini | last post by:
i hv a datagrid to which i hv bound a table...i hv the table columns to be editable...i.e read only = false....now i hv a problem...in the table there seems to be a row at the end having no values...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.