Repeater Problem

Discussion in 'ASP .Net' started by Mick Walker, Jun 25, 2007.

  1. Mick Walker

    Mick Walker Guest

    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
     
    Mick Walker, Jun 25, 2007
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
     
    Eliyahu Goldin, Jun 25, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    890
  2. Replies:
    0
    Views:
    2,916
  3. Replies:
    1
    Views:
    7,058
    Karl Seguin
    Aug 10, 2005
  4. uncensored
    Replies:
    0
    Views:
    836
    uncensored
    Oct 25, 2006
  5. Microsoft

    Repeater inside a Repeater

    Microsoft, Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    220
    Microsoft
    Aug 21, 2006
Loading...

Share This Page