468,136 Members | 1,454 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,136 developers. It's quick & easy.

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.

Jun 27 '08 #1
4 14364
Hi

Follow this article...

http://www.asp.net/Learn/Data-Access...ial-30-vb.aspx

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

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com

Jun 27 '08 #2
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="SqlDataSource1">

<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:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testdbConnectionString %>"
SelectCommand="SELECT [id], [name] FROM
[numtable]"></asp:SqlDataSource>
</form>
==============code behind===============

Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
Repeater1.ItemDataBound
Dim tb As HtmlTable = e.Item.FindControl("tb")

If e.Item.ItemIndex Mod 2 = 0 Then
tb.Style(HtmlTextWriterStyle.BackgroundColor) = "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
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:
ms****@microsoft.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" <Mi**********@noemail.noemail>
From: "Michael" <Mi**********@noemail.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.

Jun 27 '08 #3
Thanks very much for both of you. It is clear now.

"Steven Cheng [MSFT]" <st*****@online.microsoft.comwrote in message
news:MU**************@TK2MSFTNGHUB02.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="SqlDataSource1">

<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:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testdbConnectionString %>"
SelectCommand="SELECT [id], [name] FROM
[numtable]"></asp:SqlDataSource>
</form>
==============code behind===============

Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
Repeater1.ItemDataBound
Dim tb As HtmlTable = e.Item.FindControl("tb")

If e.Item.ItemIndex Mod 2 = 0 Then
tb.Style(HtmlTextWriterStyle.BackgroundColor) = "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
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:
ms****@microsoft.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" <Mi**********@noemail.noemail>
From: "Michael" <Mi**********@noemail.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.

Jun 27 '08 #4
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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>Reply-To: "Michael" <Mi**********@noemail.noemail>
From: "Michael" <Mi**********@noemail.noemail>
References: <O1**************@TK2MSFTNGP03.phx.gbl>
<MU**************@TK2MSFTNGHUB02.phx.gbl>
>In-Reply-To: <MU**************@TK2MSFTNGHUB02.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]" <st*****@online.microsoft.comwrote in message
news:MU**************@TK2MSFTNGHUB02.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="SqlDataSource1">
>>
<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:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testdbConnectionString %>"
SelectCommand="SELECT [id], [name] FROM
[numtable]"></asp:SqlDataSource>
</form>
==============code behind===============

Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
Repeater1.ItemDataBound
Dim tb As HtmlTable = e.Item.FindControl("tb")

If e.Item.ItemIndex Mod 2 = 0 Then
tb.Style(HtmlTextWriterStyle.BackgroundColor) = "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
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:
ms****@microsoft.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" <Mi**********@noemail.noemail>
From: "Michael" <Mi**********@noemail.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.


Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mamatha | last post: by
3 posts views Thread by Xerxes | last post: by
6 posts views Thread by sr | last post: by
3 posts views Thread by nma | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.