Repeater Problem

M

Mick Walker

Hi everyone, I hope you all had a great weekend.
I have a problem, and I am really not sur eon how I should address it; I
have a repeater control, which is bound to a SqlDataSource, however
within the repeater control are a number of ImageButtons, and basically
if the Data Item is empty of NULL then I wish the image on the button to
be "cross.gif" otherwise I would like it to be "tick.gif".

As I said before I really have never came accross anything of the like
before, so I am totally stumped. Here is my current code:

<asp:Repeater ID="repItems" runat="server" DataSourceID="RepDS">
<HeaderTemplate ><table cellpadding="5" cellspacing="2" >
<tr class="TableCaptions">
<td><b>UID</b></td>
<td><b>Supplier SKU</b></td>
<td><b>Linked SKU</b></td>
<td><b>Name</b></td>
<td><b>SD</b></td>
<td><b>SKD</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="RowStyle">
<td align="left" valign="top"><asp:Label ID="lblName"
runat="server" /></td>
<td><asp:ImageButton ID="IBSupplierSKU"
runat="server" ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBLinkedSKU" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBName" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBShortDescription"
runat="server" ImageUrl="~/imgs/cross.gif" /></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr class="RowStyle">
<td align="left" valign="top"><asp:Label ID="lblName"
runat="server" /></td>
<td><asp:ImageButton ID="IBSupplierSKU" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBLinkedSKU" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBName" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBShortDescription" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBSKUDescription" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
</tr>
</AlternatingItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="repDS" runat="server" ConnectionString="<%$
ConnectionStrings:DBConn %>"
SelectCommand="SELECT [UID], [SupplierSKUCode], [LinkedSKU],
[Name], [ShortDescription], [SKUDescription] FROM [Import_Lines]">
</asp:SqlDataSource>

If anyone can help, i'll gladly buy you virtual beer for the rest of
your life.

Kind Regards
Mick
 
E

Eliyahu Goldin

The most flexible way is to handle the ItemDataBound event. The event fires
for every repeater row (item) as it gets bound. You need to filter out items
that you don't want to handle, like header, footer, separator. For every
data item you get full access to the control in ItemTemplate and to the
DataItem. You can check and set any properties.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Mick Walker said:
Hi everyone, I hope you all had a great weekend.
I have a problem, and I am really not sur eon how I should address it; I
have a repeater control, which is bound to a SqlDataSource, however within
the repeater control are a number of ImageButtons, and basically if the
Data Item is empty of NULL then I wish the image on the button to be
"cross.gif" otherwise I would like it to be "tick.gif".

As I said before I really have never came accross anything of the like
before, so I am totally stumped. Here is my current code:

<asp:Repeater ID="repItems" runat="server" DataSourceID="RepDS">
<HeaderTemplate ><table cellpadding="5" cellspacing="2" >
<tr class="TableCaptions">
<td><b>UID</b></td>
<td><b>Supplier SKU</b></td>
<td><b>Linked SKU</b></td>
<td><b>Name</b></td>
<td><b>SD</b></td>
<td><b>SKD</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="RowStyle">
<td align="left" valign="top"><asp:Label ID="lblName"
runat="server" /></td>
<td><asp:ImageButton ID="IBSupplierSKU" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBLinkedSKU" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBName" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBShortDescription"
runat="server" ImageUrl="~/imgs/cross.gif" /></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr class="RowStyle">
<td align="left" valign="top"><asp:Label ID="lblName"
runat="server" /></td>
<td><asp:ImageButton ID="IBSupplierSKU" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBLinkedSKU" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBName" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBShortDescription" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
<td><asp:ImageButton ID="IBSKUDescription" runat="server"
ImageUrl="~/imgs/cross.gif" /></td>
</tr>
</AlternatingItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="repDS" runat="server" ConnectionString="<%$
ConnectionStrings:DBConn %>"
SelectCommand="SELECT [UID], [SupplierSKUCode], [LinkedSKU], [Name],
[ShortDescription], [SKUDescription] FROM [Import_Lines]">
</asp:SqlDataSource>

If anyone can help, i'll gladly buy you virtual beer for the rest of your
life.

Kind Regards
Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top