Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi this is notorious.

I have a question that I am creating my own website just like yellow pages and I am facing a problem that there are few columns in rows in the database that are not have the values and I have taken few label in the grid view like comp name and mobile and phone are few common columns and I want to hide the labels whose binded data is not present in the database.

Can this be done in any possible means?
Posted
Updated 27-Feb-11 11:57am
v2

Using a GridView?

There are two properties of the columns:

ConvertEmptyStringToNull
NullDisplayText

Either or both might be of use to you.

If you are using TemplateFields, set the default text of the label to an empty string. (Not tested, but should do it.)
 
Share this answer
 
use to bind visibility like

<asp:Label Id="id" runat="server" Text="<%#Eval("fld")%>" Visible="<%#Eval("fld")!=DBNull.Value && !string.IsNullOrEmpty( Convert.ToString(Eval("fld"))) %>" />


--Pankaj
 
Share this answer
 
v3
<asp:gridview id=""GridView1"" runat=""server"" width=""100%"" height=""100%"<br" mode="hold" xmlns:asp="#unknown" />Font-Bold="False" AutoGenerateColumns="False" AllowPaging="True"onpageindexchanging="GridView1_PageIndexChanging" PageSize="5"
GridLines="None"><RowStyle HorizontalAlign="Left" />
<Columns>
<asp:TemplateField HeaderText="Leads">
<ItemTemplate>
<br />
<asp:Label ID="Label1" runat="server" Text='<%# Bind("company_name") %>' Font-Bold="True" Font-Size="Medium"
ForeColor="Red"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text='<%#Bind("work_description")%>'></asp:Label>
<asp:Label ID="Label4" runat="server" Text='<%#Bind("contact_person") %>'></asp:Label>
<br /><asp:Label ID="Label5" runat="server" Text="Address : ">
</asp:Label><asp:Label ID="Label6" runat="server" Text='<%#Bind("Address") %>'></asp:Label>
<br /><asp:Label ID="Label7" runat="server" Text="Mobile : "></asp:Label>
<asp:Label ID="Label8" runat="server" Text='<%#Bind("Mobile") %>'></asp:Label>
<br />
<asp:Label ID="Label9" runat="server" Text="E-mail : "></asp:Label>
<asp:Label ID="Label10" runat="server" Text='<%#Bind("email") %>'></asp:Label>
<br />
<asp:Label ID="Label11" runat="server" Text="Website : "></asp:Label>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Bind("website") %>' Text='<%#Bind("website") %>' Target="_blank"></asp:HyperLink>
<hr style="size:2; color:Blue;" /><br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
&nbsp&nbsp&nbsp&nbsp    <asp:Image ID="Image1" runat="server" Visible="False" />&nbsp&nbsp&nbsp&nbsp
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle HorizontalAlign="Center" VerticalAlign="Top" />
<HeaderStyle ForeColor="White" Font-Bold="True"
Font-Names="Bookman Old Style" Font-Size="Large" Height="0px" />
</asp:GridView>



i think this better explian the situation in the above gridview i want that if there is no data present in the the email label which is bounded is aleready hidden but its cation label is present that should also get hidden.
 
Share this answer
 
Comments
GenJerDan 28-Feb-11 12:57pm    
You could do the same for Label9 as Pankaj shows, just don't do the eval for the Text property...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900