Hi,

I'm really struggling with creating an if statement with the content of a data repeater.

I'm looking for somthing along the following lines...

<%IF Container.DataItem( "fldExtraImage1" ) is not dbnull THEN

<img src="images/Extras/<%# Container.DataItem( "fldExtraImage1" ) %>" alt="<%# Container.DataItem( "fldExtraTitle1" ) %>">

ELSE IF Container.DataItem( "fldExtraImage2" ) is not dbnull THEN

<img src="images/Extras/<%# Container.DataItem( "fldExtraImage2" ) %>" alt="<%# Container.DataItem( "fldExtraTitle2" ) %>">


Below is the code that I need to apply it to...

<%@ Import Namespace="System.Data.SqlClient" %>

<Script Runat="Server">

Sub Page_Load
  Dim conPubs As SqlConnection
  Dim cmdSelect As SqlCommand
  Dim dtrAuthors As SqlDataReader

  ' Retrieve records from database
  conPubs = New SqlConnection( "Server=xyz" )
  cmdSelect = New SqlCommand( "SELECT tblMain.*, tblRetailer.*, tblItem.*, tblItemVersion.fldItemVersion FROM tblMain INNER JOIN tblRetailer ON tblMain.fldRetailerID = tblRetailer.fldRetailerID INNER JOIN tblItem ON tblMain.fldItemID = tblItem.fldItemID INNER JOIN tblItemVersion ON tblItem.fldItemVersionID = tblItemVersion.fldItemVersionID WHERE (tblItem.fldItemTitle LIKE '3' and tblMain.fldNotAvailable is null)", conPubs )
  conPubs.Open()
  dtrAuthors = cmdSelect.ExecuteReader()

  ' Bind to Repeater
  rptAuthors.DataSource = dtrAuthors
  rptAuthors.DataBind()

  dtrAuthors.Close()
  conPubs.Close()

End Sub

</Script>

<html>
<head><title>RepeaterTable.aspx</title></head>
<body>
<form Runat="Server">

<asp:Repeater
  ID="rptAuthors"
  Runat="Server">

  <HeaderTemplate>
    <table border=1 cellpadding=4>
    <tr bgcolor="#eeeeee">
      <th>Retailer</th>
      <th>Items</th>
      <th>Price</th>
    </tr>
  </HeaderTemplate>

  <ItemTemplate>
		<img src="images/Extras/<%# Container.DataItem( "fldExtraImage1" ) %>" alt="<%# Container.DataItem( "fldExtraTitle1" ) %>">
		<img src="images/Extras/<%# Container.DataItem( "fldExtraImage2" ) %>" alt="<%# Container.DataItem( "fldExtraTitle2" ) %>">
		<img src="images/Extras/<%# Container.DataItem( "fldExtraImage3" ) %>" alt="<%# Container.DataItem( "fldExtraTitle3" ) %>">
		<img src="images/Extras/<%# Container.DataItem( "fldExtraImage4" ) %>" alt="<%# Container.DataItem( "fldExtraTitle4" ) %>">
		<img src="images/Extras/<%# Container.DataItem( "fldExtraImage5" ) %>" alt="<%# Container.DataItem( "fldExtraTitle5" ) %>">
  </ItemTemplate>



  <FooterTemplate>
    </table>
  </FooterTemplate>

</asp:Repeater>

</form>
</body>
</html>

Any help on this would be greatly appreciated.

Squirell

void Repeater_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
        {

           if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
               Image myImage = (Image)e.Item.FindControl("img1");

                if( string.IsNullOrEmpty(myImage.ImageUrl) )
                {
                    myImage.ImageUrl = "blankImage";
                }

            }
        }

Thanks for the reply. I have tried to put your suggestion in the code and I get...

'Compiler Error Message: BC30108: 'void' is a type and cannot be used as an expression.

Source Error:

Line 21: conPubs.Close()
Line 22:
Line 23: void Repeater_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
Line 24: {
Line 25:

Below is the code where I have implamented you suggestion. Any more help would be greatly appreciated.

<%@ Import Namespace="System.Data.SqlClient" %>

<Script Runat="Server">

Sub Page_Load
  Dim conPubs As SqlConnection
  Dim cmdSelect As SqlCommand
  Dim dtrAuthors As SqlDataReader

  ' Retrieve records from database
  conPubs = New SqlConnection( "Server=XYZ" )
  cmdSelect = New SqlCommand( "SELECT tblMain.*, tblRetailer.*, tblItem.*, tblItemVersion.fldItemVersion FROM tblMain INNER JOIN tblRetailer ON tblMain.fldRetailerID = tblRetailer.fldRetailerID INNER JOIN tblItem ON tblMain.fldItemID = tblItem.fldItemID INNER JOIN tblItemVersion ON tblItem.fldItemVersionID = tblItemVersion.fldItemVersionID WHERE (tblItem.fldItemTitle LIKE '3' and tblMain.fldNotAvailable is null)", conPubs )
  conPubs.Open()
  dtrAuthors = cmdSelect.ExecuteReader()

  ' Bind to Repeater
  rptAuthors.DataSource = dtrAuthors
  rptAuthors.DataBind()

  dtrAuthors.Close()
  conPubs.Close()


void rptAuthors(Object Sender, RepeaterItemEventArgs e)
{

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Image myImage = (Image)e.Item.FindControl("img1");

if( string.IsNullOrEmpty(myImage.ImageUrl) )
{
myImage.ImageUrl = "blankImage";
}

}
}

End Sub







</Script>

<html>
<head><title>RepeaterTable.aspx</title></head>
<body>
<form Runat="Server">

<asp:Repeater
  ID="rptAuthors"
  Runat="Server">

  <HeaderTemplate>
    <table border=1 cellpadding=4>
    <tr bgcolor="#eeeeee">
      <th>Retailer</th>
      <th>Items</th>
      <th>Price</th>
    </tr>
  </HeaderTemplate>

  <ItemTemplate>

  

<img ID="img1" SRC='<%# Container.DataItem( "fldExtraImage1" ) %>' Runat="Server">
<img ID="img2" SRC='<%# Container.DataItem( "fldExtraImage2" ) %>' Runat="Server">
<img ID="img3" SRC='<%# Container.DataItem( "fldExtraImage3" ) %>' Runat="Server">
<img ID="img4" SRC='<%# Container.DataItem( "fldExtraImage4" ) %>' Runat="Server">
<img  ID="img5" SRC='<%# Container.DataItem( "fldExtraImage5" ) %>' Runat="Server">



	
	</tr>

  </ItemTemplate>



  <FooterTemplate>
    </table>
  </FooterTemplate>

</asp:Repeater>

</form>
</body>
</html>

Write the below code in the code behind,

protected void Repeater_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
        {
        }

Hi tonykmathew,

Thanks again for the prompt reply. I'm nowgetting the following error...

Compiler Error Message: BC30205: End of statement expected.

Source Error:

Line 22:
Line 23:
Line 24: protected void Repeater_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
Line 25:
Line 26: {

Any ideas?

Thanks again.

<%@ Import Namespace="System.Data.SqlClient" %>

<Script Runat="Server">

Sub Page_Load
  Dim conPubs As SqlConnection
  Dim cmdSelect As SqlCommand
  Dim dtrAuthors As SqlDataReader

  ' Retrieve records from database
  conPubs = New SqlConnection( "XYZ" )
  cmdSelect = New SqlCommand( "SELECT tblMain.*, tblRetailer.*, tblItem.*, tblItemVersion.fldItemVersion FROM tblMain INNER JOIN tblRetailer ON tblMain.fldRetailerID = tblRetailer.fldRetailerID INNER JOIN tblItem ON tblMain.fldItemID = tblItem.fldItemID INNER JOIN tblItemVersion ON tblItem.fldItemVersionID = tblItemVersion.fldItemVersionID WHERE (tblItem.fldItemTitle LIKE '3' and tblMain.fldNotAvailable is null)", conPubs )
  conPubs.Open()
  dtrAuthors = cmdSelect.ExecuteReader()

  ' Bind to Repeater
  rptAuthors.DataSource = dtrAuthors
  rptAuthors.DataBind()

  dtrAuthors.Close()
  conPubs.Close()


protected void Repeater_ItemDataBound(Object Sender, RepeaterItemEventArgs e)

{

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Image myImage = (Image)e.Item.FindControl("img1");

if( string.IsNullOrEmpty(myImage.ImageUrl) )
{
myImage.ImageUrl = "blankImage";
}

}
}

 

End Sub







</Script>

<html>
<head><title>RepeaterTable.aspx</title></head>
<body>
<form Runat="Server">

<asp:Repeater
  ID="rptAuthors"
  Runat="Server">

  <HeaderTemplate>
    <table border=1 cellpadding=4>
    <tr bgcolor="#eeeeee">
      <th>Retailer</th>
      <th>Items</th>
      <th>Price</th>
    </tr>
  </HeaderTemplate>

  <ItemTemplate>
    <tr>
      <td>
			<img src="images/retailers/<%# Container.DataItem( "fldRetailerLogo" ) %>" alt="<%# Container.DataItem( "fldRetailerName" ) %>"> 
	  </td>
	  <td>
		<img src="images/Console/<%# Container.DataItem( "fldItemImage" ) %>" alt="<%# Container.DataItem( "fldItemVersion" ) %>&nbsp;<%# Container.DataItem( "fldItemTitle" ) %>"><img src="images/Extras/<%# Container.DataItem( "fldExtraImage1" ) %>" alt="<%# Container.DataItem( "fldExtraTitle1" ) %>">
	  </td>      
	  <td>
		<%# Container.DataItem( "fldDeallink" ) %>
	  </td>
	  <td>
		&pound;<%# Container.DataItem( "fldPrice" ) %>
	  </td>
  

<img ID="img1" SRC='<%# Container.DataItem( "fldExtraImage1" ) %>' Runat="Server">
<img ID="img2" SRC='<%# Container.DataItem( "fldExtraImage2" ) %>' Runat="Server">
<img ID="img3" SRC='<%# Container.DataItem( "fldExtraImage3" ) %>' Runat="Server">
<img ID="img4" SRC='<%# Container.DataItem( "fldExtraImage4" ) %>' Runat="Server">
<img  ID="img5" SRC='<%# Container.DataItem( "fldExtraImage5" ) %>' Runat="Server">



	
	</tr>

  </ItemTemplate>



  <FooterTemplate>
    </table>
  </FooterTemplate>

</asp:Repeater>

</form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.