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>