How to change the row color of the Repeater based on some condition?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael

    How to change the row color of the Repeater based on some condition?

    I have a repeater web control. Currently I want to change some row's color
    based on defined condition. Is there any code sample demonstrating how to
    accomplish it?

    Thanks.

  • Munna

    #2
    Re: How to change the row color of the Repeater based on somecondition?

    Hi

    Follow this article...

    Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.


    The main technique is to use itemdatabound event to format rows...

    Best of luck

    Munna




    Comment

    • Steven Cheng [MSFT]

      #3
      RE: How to change the row color of the Repeater based on some condition?

      Hi Michael,

      As Munna has suggested, for repeater control ,if the conditional code logic
      is complex (and not convenient to implement via inline databinding
      expression), you can consider using ItemDataBound event. Here is a simple
      sample which use repeater to display multiple html table. And I use
      "ItemDatdaBound " event to set the background color of each table:


      ==========aspx page=========== =========
      <asp:Repeater ID="Repeater1" runat="server" DataSourceID="S qlDataSource1">

      <ItemTemplate >
      <table id="tb" runat="server">
      <tr>
      <td>
      <asp:Label ID="Label1" runat="server"
      Text="Label"></asp:Label>
      <asp:Button ID="Button2" runat="server" Text="Button" />
      </td>
      </tr>
      </table>
      </ItemTemplate>

      </asp:Repeater>
      <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
      ConnectionStrin g="<%$ ConnectionStrin gs:testdbConnec tionString %>"
      SelectCommand=" SELECT [id], [name] FROM
      [numtable]"></asp:SqlDataSour ce>
      </form>
      ==============c ode behind========= ======

      Protected Sub Repeater1_ItemD ataBound(ByVal sender As Object, ByVal e
      As System.Web.UI.W ebControls.Repe aterItemEventAr gs) Handles
      Repeater1.ItemD ataBound
      Dim tb As HtmlTable = e.Item.FindCont rol("tb")

      If e.Item.ItemInde x Mod 2 = 0 Then
      tb.Style(HtmlTe xtWriterStyle.B ackgroundColor) = "yellow"
      End If


      End Sub
      =============== =============== ===

      Here are some other web articles mentioned some samples of using
      ItemDataBound event to customize repeater or datalist control:

      #ASP.NET Tip: Use the ItemDataBound Event of a Repeater


      #Formatting the DataList and Repeater Based Upon Data
      Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.



      Sincerely,

      Steven Cheng

      Microsoft MSDN Online Support Lead


      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      Gain technical skills through documentation and training, earn certifications and connect with the community

      ications.

      Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
      where an initial response from the community or a Microsoft Support
      Engineer within 1 business day is acceptable. Please note that each follow
      up response may take approximately 2 business days as the support
      professional working with you may need further investigation to reach the
      most efficient resolution. The offering is not appropriate for situations
      that require urgent, real-time or phone-based interactions or complex
      project analysis and dump analysis issues. Issues of this nature are best
      handled working with a dedicated Microsoft Support Engineer by contacting
      Microsoft Customer Support Services (CSS) at
      http://msdn.microsoft.com/subscripti...t/default.aspx.
      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.
      --------------------
      >Reply-To: "Michael" <Michael_MSDN@n oemail.noemail>
      >From: "Michael" <Michael_MSDN@n oemail.noemail>
      >Subject: How to change the row color of the Repeater based on some
      condition?
      >Date: Thu, 19 Jun 2008 14:34:13 +0800
      >
      >I have a repeater web control. Currently I want to change some row's color
      >based on defined condition. Is there any code sample demonstrating how to
      >accomplish it?
      >
      >Thanks.
      >
      >

      Comment

      • Michael

        #4
        Re: How to change the row color of the Repeater based on some condition?

        Thanks very much for both of you. It is clear now.

        "Steven Cheng [MSFT]" <stcheng@online .microsoft.comw rote in message
        news:MUI9PCf0IH A.3644@TK2MSFTN GHUB02.phx.gbl. ..
        Hi Michael,
        >
        As Munna has suggested, for repeater control ,if the conditional code
        logic
        is complex (and not convenient to implement via inline databinding
        expression), you can consider using ItemDataBound event. Here is a simple
        sample which use repeater to display multiple html table. And I use
        "ItemDatdaBound " event to set the background color of each table:
        >
        >
        ==========aspx page=========== =========
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="S qlDataSource1">
        >
        <ItemTemplate >
        <table id="tb" runat="server">
        <tr>
        <td>
        <asp:Label ID="Label1" runat="server"
        Text="Label"></asp:Label>
        <asp:Button ID="Button2" runat="server" Text="Button" />
        </td>
        </tr>
        </table>
        </ItemTemplate>
        >
        </asp:Repeater>
        <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
        ConnectionStrin g="<%$ ConnectionStrin gs:testdbConnec tionString %>"
        SelectCommand=" SELECT [id], [name] FROM
        [numtable]"></asp:SqlDataSour ce>
        </form>
        ==============c ode behind========= ======
        >
        Protected Sub Repeater1_ItemD ataBound(ByVal sender As Object, ByVal e
        As System.Web.UI.W ebControls.Repe aterItemEventAr gs) Handles
        Repeater1.ItemD ataBound
        Dim tb As HtmlTable = e.Item.FindCont rol("tb")
        >
        If e.Item.ItemInde x Mod 2 = 0 Then
        tb.Style(HtmlTe xtWriterStyle.B ackgroundColor) = "yellow"
        End If
        >
        >
        End Sub
        =============== =============== ===
        >
        Here are some other web articles mentioned some samples of using
        ItemDataBound event to customize repeater or datalist control:
        >
        #ASP.NET Tip: Use the ItemDataBound Event of a Repeater

        >
        #Formatting the DataList and Repeater Based Upon Data
        Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.

        >
        >
        Sincerely,
        >
        Steven Cheng
        >
        Microsoft MSDN Online Support Lead
        >
        >
        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.
        >
        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        Gain technical skills through documentation and training, earn certifications and connect with the community

        ications.
        >
        Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 1 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions or complex
        project analysis and dump analysis issues. Issues of this nature are best
        handled working with a dedicated Microsoft Support Engineer by contacting
        Microsoft Customer Support Services (CSS) at
        http://msdn.microsoft.com/subscripti...t/default.aspx.
        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no
        rights.
        --------------------
        >>Reply-To: "Michael" <Michael_MSDN@n oemail.noemail>
        >>From: "Michael" <Michael_MSDN@n oemail.noemail>
        >>Subject: How to change the row color of the Repeater based on some
        condition?
        >>Date: Thu, 19 Jun 2008 14:34:13 +0800
        >
        >>
        >>I have a repeater web control. Currently I want to change some row's color
        >>based on defined condition. Is there any code sample demonstrating how to
        >>accomplish it?
        >>
        >>Thanks.
        >>
        >>
        >

        Comment

        • Steven Cheng [MSFT]

          #5
          Re: How to change the row color of the Repeater based on some condition?

          You're welcome Michael,

          If there is anything else we can help, please feel free to post here.

          Sincerely,

          Steven Cheng

          Microsoft MSDN Online Support Lead


          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.

          =============== =============== =============== =====
          Get notification to my posts through email? Please refer to
          Gain technical skills through documentation and training, earn certifications and connect with the community

          ications.
          =============== =============== =============== =====
          This posting is provided "AS IS" with no warranties, and confers no rights.
          --------------------
          >Reply-To: "Michael" <Michael_MSDN@n oemail.noemail>
          >From: "Michael" <Michael_MSDN@n oemail.noemail>
          >References: <O1oN$Zd0IHA.22 92@TK2MSFTNGP03 .phx.gbl>
          <MUI9PCf0IHA.36 44@TK2MSFTNGHUB 02.phx.gbl>
          >In-Reply-To: <MUI9PCf0IHA.36 44@TK2MSFTNGHUB 02.phx.gbl>
          >Subject: Re: How to change the row color of the Repeater based on some
          condition?
          >Date: Fri, 20 Jun 2008 11:26:47 +0800
          >
          >Thanks very much for both of you. It is clear now.
          >
          >"Steven Cheng [MSFT]" <stcheng@online .microsoft.comw rote in message
          >news:MUI9PCf0I HA.3644@TK2MSFT NGHUB02.phx.gbl ...
          >Hi Michael,
          >>
          >As Munna has suggested, for repeater control ,if the conditional code
          >logic
          >is complex (and not convenient to implement via inline databinding
          >expression), you can consider using ItemDataBound event. Here is a simple
          >sample which use repeater to display multiple html table. And I use
          >"ItemDatdaBoun d" event to set the background color of each table:
          >>
          >>
          >==========as px page=========== =========
          ><asp:Repeate r ID="Repeater1" runat="server"
          DataSourceID="S qlDataSource1">
          >>
          > <ItemTemplate >
          > <table id="tb" runat="server">
          > <tr>
          > <td>
          > <asp:Label ID="Label1" runat="server"
          >Text="Label" ></asp:Label>
          > <asp:Button ID="Button2" runat="server" Text="Button" />
          > </td>
          > </tr>
          > </table>
          > </ItemTemplate>
          >>
          > </asp:Repeater>
          > <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
          > ConnectionStrin g="<%$ ConnectionStrin gs:testdbConnec tionString %>"
          > SelectCommand=" SELECT [id], [name] FROM
          >[numtable]"></asp:SqlDataSour ce>
          > </form>
          >============== code behind========= ======
          >>
          > Protected Sub Repeater1_ItemD ataBound(ByVal sender As Object, ByVal e
          >As System.Web.UI.W ebControls.Repe aterItemEventAr gs) Handles
          >Repeater1.Item DataBound
          > Dim tb As HtmlTable = e.Item.FindCont rol("tb")
          >>
          > If e.Item.ItemInde x Mod 2 = 0 Then
          > tb.Style(HtmlTe xtWriterStyle.B ackgroundColor) = "yellow"
          > End If
          >>
          >>
          > End Sub
          >============== =============== ====
          >>
          >Here are some other web articles mentioned some samples of using
          >ItemDataBoun d event to customize repeater or datalist control:
          >>
          >#ASP.NET Tip: Use the ItemDataBound Event of a Repeater
          >http://www.codeguru.com/csharp/.net/...le.php/c12065/
          >>
          >#Formatting the DataList and Repeater Based Upon Data
          >http://www.asp.net/Learn/Data-Access...ial-30-vb.aspx
          >>
          >>
          >Sincerely,
          >>
          >Steven Cheng
          >>
          >Microsoft MSDN Online Support Lead
          >>
          >>
          >Delighting our customers is our #1 priority. We welcome your comments and
          >suggestions about how we can improve the support we provide to you.
          Please
          >feel free to let my manager know what you think of the level of service
          >provided. You can send feedback directly to my manager at:
          >msdnmg@microsof t.com.
          >>
          >============== =============== =============== ======
          >Get notification to my posts through email? Please refer to
          >>
          http://msdn.microsoft.com/subscripti...ult.aspx#notif
          >ications.
          >>
          >Note: The MSDN Managed Newsgroup support offering is for non-urgent
          issues
          >where an initial response from the community or a Microsoft Support
          >Engineer within 1 business day is acceptable. Please note that each
          follow
          >up response may take approximately 2 business days as the support
          >professional working with you may need further investigation to reach the
          >most efficient resolution. The offering is not appropriate for situations
          >that require urgent, real-time or phone-based interactions or complex
          >project analysis and dump analysis issues. Issues of this nature are best
          >handled working with a dedicated Microsoft Support Engineer by contacting
          >Microsoft Customer Support Services (CSS) at
          >http://msdn.microsoft.com/subscripti...t/default.aspx.
          >============== =============== =============== ======
          >This posting is provided "AS IS" with no warranties, and confers no
          >rights.
          >--------------------
          >>>Reply-To: "Michael" <Michael_MSDN@n oemail.noemail>
          >>>From: "Michael" <Michael_MSDN@n oemail.noemail>
          >>>Subject: How to change the row color of the Repeater based on some
          >condition?
          >>>Date: Thu, 19 Jun 2008 14:34:13 +0800
          >>
          >>>
          >>>I have a repeater web control. Currently I want to change some row's
          color
          >>>based on defined condition. Is there any code sample demonstrating how to
          >>>accomplish it?
          >>>
          >>>Thanks.
          >>>
          >>>
          >>
          >
          >

          Comment

          Working...