473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 15295
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sugapablo | last post by:
Can anyone help me out with some code to change three table cells (<td>) when one is hovered over? I have a calendar grid where each day is made up of three table cells and I want all three to...
2
by: Xiphias | last post by:
Hi, Im trying to change the color of a text box on a report that im printing from a form. On the form I got a check box that has to tricker the color of that textbox on the printed report....
1
by: Robbo | last post by:
Hello, I created a datagrid with a few hyperlink columns.. How do i change the color of the hyperlink itself? BLUE is a bit bad on my datagrid color scheme. Thanks, Rob
2
by: HS1 | last post by:
Hello all Do you know how to change color of a button when the mouse is over it (like a button in manu bar can change its color in a website) in VB.net Thank you S.Hoa
3
by: Mamatha | last post by:
Hi I want to change the color of icon,How it can be opened? and how can i change color. If any one knows please let me know Thanks in advance. Mamatha
3
by: Xerxes | last post by:
Hi, I have 3 images of the same product in 3 different colors. I want to display the correct color product based on what color is selected using a dropdown. Can you please tell me how I can do...
6
by: sr | last post by:
please help i have problem: I know how to change color row in table when my mouse is over on this row and change color to another color when my mouse is out from this row. but i dont know how to...
0
by: nicolass | last post by:
Hi, Im new in c# :) I wonder how to change color of some cell if there is some criteria. ie. if value in cell = John then color of that cell is Red This very easy in PHP but c#.. :(
3
by: nma | last post by:
Hi How do I make the cell change color to 'black' after I click on it. The cell will remain black color until I click another cell which will also change to black. I can do the mouseover and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.