Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to change the row color of the Repeater based on some condition?

Reply
Thread Tools

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

 
 
Michael
Guest
Posts: n/a
 
      06-19-2008
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.

 
Reply With Quote
 
 
 
 
Munna
Guest
Posts: n/a
 
      06-19-2008
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

 
Reply With Quote
 
 
 
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      06-19-2008
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:
http://www.velocityreviews.com/forums/(E-Mail Removed).

==================================================
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" <(E-Mail Removed)>
>From: "Michael" <(E-Mail Removed)>
>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.
>
>


 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      06-20-2008
Thanks very much for both of you. It is clear now.

"Steven Cheng [MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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:
> (E-Mail Removed).
>
> ==================================================
> 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" <(E-Mail Removed)>
>>From: "Michael" <(E-Mail Removed)>
>>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.
>>
>>

>


 
Reply With Quote
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      06-20-2008
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:
(E-Mail Removed).

==================================================
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" <(E-Mail Removed)>
>From: "Michael" <(E-Mail Removed)>
>References: <O1oN$(E-Mail Removed)>

<(E-Mail Removed)>
>In-Reply-To: <(E-Mail Removed)>
>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]" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> 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:
>> (E-Mail Removed).
>>
>> ==================================================
>> 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" <(E-Mail Removed)>
>>>From: "Michael" <(E-Mail Removed)>
>>>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.
>>>
>>>

>>

>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
change row color of empty row =?Utf-8?B?aWdvdHlvdXJkb3RuZXQ=?= ASP .Net 3 10-24-2006 12:11 PM
Checkbox and dropdownlist row in repeater row =?Utf-8?B?UmljaGFyZEg=?= ASP .Net 2 03-24-2006 10:48 AM
Set repeater row background color based on data value - how? James Radke ASP .Net Web Controls 1 01-21-2004 05:36 AM
How to change the color of a row (Repeater)? george d lake ASP .Net 0 07-08-2003 04:02 PM



Advertisments