Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 January 4th, 2004, 07:17 AM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid

Hi,


I have a datagrid that receives its values from a db. I have included an image column that is also received from the db. Everything seems to be working fine.
Now, I am trying to add response.write ("No picture available") if there is no image but I am not sure how to do that.
Can someone please help ?
Thanks



ASPX.VB

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Put user code to initialize the page here

        AD_ApprovedState = Request.QueryString("aprst")


        If Not Page.IsPostBack Then

            fillTable()

        End If

    End Sub

    Public Sub fillTable()



        If AD_ApprovedState = "" Then

            AD_ApprovedState = "0"

        End If

        cmd = oConn.CreateCommand

        cmd.CommandText = "select *, 'adDetail.aspx?sid=' + @sid + '&ad_id=' + CAST(ad_id AS NVARCHAR(16))+ '&sub_id=' + CAST(sub_id AS NVARCHAR(16))+ '&cat_id=' + CAST(cat_id AS NVARCHAR(16)) AS url_str FROM mysite_mdb...ads where ad_approved=@AD_ApprovedState"

        cmd.Parameters.Add("@sid", sid)

        cmd.Parameters.Add("@AD_ApprovedState", AD_ApprovedState)

        Dim da As New SqlDataAdapter(cmd)

        Dim dt As New DataTable("ads")

        da.Fill(dt)
        DataGrid1.DataSource = dt

        DataGrid1.DataBind()

    End Sub



    Sub doPaging(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged

        DataGrid1.CurrentPageIndex = e.NewPageIndex

        fillTable()

    End Sub





End Class



ASPX:

<asp:datagrid id="DataGrid1" runat="server" HorizontalAlign="Right" AutoGenerateColumns="False"
GridLines="Horizontal" CellPadding="6" BackColor="White" BorderWidth="1px" BorderStyle="None"
BorderColor="#E7E7FF" OnPageIndexChanged="doPaging" PagerStyle-HorizontalAlign="Center" AllowPaging="True">
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
<FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>

<Columns>

    <asp:BoundColumn DataField="ad_id" HeaderText="AD ID"></asp:BoundColumn>
<asp:HyperLinkColumn Text="ad_title" Target="_self" DataNavigateUrlField="url_str" DataTextField="ad_title"
HeaderText="TITLE"></asp:HyperLinkColumn>

<asp:TemplateColumn HeaderText="IMAGE">
<ItemTemplate>
<Img src="http://www.ybay.co.il/images/<%#Container.DataItem("ad_image") %>" id="img" height="100" width =100>
</ItemTemplate>

</asp:TemplateColumn>
<asp:BoundColumn DataField="ad_quantity" HeaderText="quantity"></asp:BoundColumn>

<asp:BoundColumn DataField="ad_dated" HeaderText="DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="ad_expired" HeaderText="EXPIRY DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="ad_man" HeaderText="SALESPERSON"></asp:BoundColumn>

</Columns>

<PagerStyle HorizontalAlign="Center" BackColor="White" Mode="NumericPages"></PagerStyle>

</asp:datagrid>





 
Old January 5th, 2004, 10:23 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What does the data look like when there is no picture? Is the DB value NULL or blank? If it's NULL then perhaps you could handle the check in the database and create a "no image found" image.

SELECT COALESCE(ad_image, 'noimage.gif')...

COALESCE will return the first non-NULL value.

This would be very clean and require nothing more in the markup.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom paging in Datagrid with datagrid page count madhusrp ASP.NET 1.0 and 1.1 Professional 12 June 2nd, 2008 01:15 PM
User COntrol Datagrid inside datagrid rodmcleay ASP.NET 1.0 and 1.1 Professional 3 April 14th, 2007 10:11 AM
Creating DataGrid In Repeater/DataGrid liduwan ASP.NET 1.0 and 1.1 Professional 9 March 6th, 2007 03:31 PM
datagrid ajaidass ADO.NET 2 March 1st, 2007 05:36 PM
Need help regarding datagrid ngsharmila .NET Framework 1.x 1 February 1st, 2006 12:55 AM





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