Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2007, 07:02 AM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default hiding an image

Dears, i am displaying information from a database using SqlDataSource and datalist, the database is showing 3 fields, an image and 2 labels. How can i hide the image if the value from the database id null.

the SQL DATASOURCE is:

<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:peaceConnectionString1 %>"
SelectCommand="SELECT [newsid], [newstitle], [adddate], [news], [newspic] FROM [news] WHERE ([newsid] = @newsid)"><SelectParameters>
<asp:QueryStringParameter Name="newsid" QueryStringField="newsid" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

The Datalist is:

    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
        <ItemTemplate>
            <table style="width: 720px">
                <tr>
                    <td style="width: 720px; text-align: center">
                        <asp:Image ID="Image2"
                        runat="server"
                        ImageUrl='<%# Eval("newspic", "images/news/{0}") %>'
                        BorderColor="White"
                        BorderWidth="2px"
                        Visible='<%# Eval("newspic") %>'

                        />
                        <br />

                    </td>
                </tr>
                <tr>
                    <td style="width: 720px; text-align: left">
                        <asp:Label ID="adddateLabel" runat="server" Text='<%# Eval("adddate", "{0:d}") %>' CssClass="blue12"></asp:Label><br />
                        <asp:Image ID="Image1" runat="server" ImageUrl="~/images/arr.gif" />&nbsp;
                        <asp:Label ID="Label2" runat="server" CssClass="sitetext" Text='<%# Eval("newstitle") %>' Font-Bold="True"></asp:Label>
                        <br />
                        <br />
                        <asp:Label ID="Label1" runat="server" CssClass="sitetext" Text='<%# Eval("news", "{0}") %>'></asp:Label><br />
                        &nbsp;</td>
                </tr>
                <tr>
                    <td style="width: 720px; text-align: left">
                    </td>
                </tr>
                <tr>
                    <td style="width: 720px; height: 18px; text-align: center">
                        <asp:HyperLink ID="HyperLink1" runat="server" CssClass="copyright" NavigateUrl="~/news.aspx">Back to News</asp:HyperLink></td>
                </tr>
            </table>
            &nbsp;
        </ItemTemplate>
    </asp:DataList>
 
Old August 20th, 2007, 08:16 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well one approach could be the ItemDataBound event of datalist, the code could be as below:

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                if (DataBinder.Eval(e.Item.DataItem, "newspic") == DBNull.Value)
                {
                    ((Image)e.Item.FindControl("Image2")).Visible = false;
                }
            }
        }

Regards
Mike

Don't expect too much, too soon.
 
Old August 20th, 2007, 12:07 PM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I need the code in VB, please reply






Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding sub headers.... rupen Crystal Reports 6 May 14th, 2007 04:56 AM
hiding footer. rupen Javascript How-To 4 April 12th, 2007 06:07 PM
Hiding scrollbars. rupen HTML Code Clinic 1 September 5th, 2005 07:00 AM
hiding in we config vohra_vikas ADO.NET 2 September 28th, 2004 08:36 AM
Hiding Keystrokes kromlic Beginning VB 6 3 June 12th, 2003 04:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.