Solved

change colour of repeater control in asp.net c#

Posted on 2016-09-30
7
51 Views
Last Modified: 2016-10-10
Hi experts,

I need blue colour in background of repeater control. I am using repeater cntrl like below. But unable to change the background colour.

Can you please suggest what is the best way to achieve that ?


 <asp:Repeater ID="rptPagerHeader" runat="server">
                                  <ItemTemplate>
                                        <asp:LinkButton ID="lnkPageHeader" runat="server" Text = '<%#Eval("Text") %>' CommandArgument = '<%# Eval("Value") %>' Enabled = '<%# Eval("Enabled") %>' OnClick = "Page_ChangedHeader"></asp:LinkButton>
                                    </ItemTemplate>                                                      
                   </asp:Repeater>
0
Comment
Question by:satmisha
  • 4
  • 2
7 Comments
 
LVL 39

Expert Comment

by:Kyle Abrahams
Comment Utility
surround the repeater in a div and set the background of the div to blue.  then anything inside the div (eg: repeater and all controls) will also have a blue background unless there's a higher priority style rule.
0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
Comment Utility
HI satmisha,

Please check the sample below code. For change the background colour you have to add color in <td>

            <asp:Repeater ID="Repeater1" runat="server">
                <HeaderTemplate>
                    <table>
                        <tr>
                            <td style="background-color: Gray; width: 100px;">Id</td>
                            <td style="background-color: Gray; width: 100px;">Name</td>
                            <td style="background-color: Gray; width: 100px;">Age</td>
                            <td style="background-color: Gray; width: 100px;">Salary</td>
                            <td style="background-color: Gray; width: 100px;">Country</td>
                            <td style="background-color: Gray; width: 100px;">City</td>
                        </tr>
                    </table>
                </HeaderTemplate>
                <ItemTemplate>
                    <table>
                        <tr>
                            <td style="background-color: blue; width: 100px;">
                                <asp:Label ID="lblId" runat="server" Text='<%#Bind("id")%>'></asp:Label>
                            </td>
                            <td style="background-color: blue; width: 100px;">
                                <asp:Label ID="lblName" runat="server" Text='<%#Bind("name")%>'></asp:Label>
                            </td>
                            <td style="background-color: blue; width: 100px;">
                                <asp:Label ID="lblAge" runat="server" Text='<%#Bind("age")%>'></asp:Label>
                                <td style="background-color: blue; width: 100px;">
                                    <asp:Label ID="lblSalary" runat="server" Text='<%#Bind("salary")%>'></asp:Label>
                                </td>
                                <td style="background-color: blue; width: 100px;">
                                    <asp:Label ID="lblCountry" runat="server" Text='<%#Bind("country")%>'></asp:Label>
                                    <td style="background-color: blue; width: 100px;">
                                        <asp:Label ID="lblCity" runat="server" Text='<%#Bind("city")%>'></asp:Label>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:Repeater>

Open in new window


Regards,
Tapan Pattanaik
0
 

Author Comment

by:satmisha
Comment Utility
Thanks Tapan,

TD colour suggestion worked but getting one small issue i.e. width of the td which is in repeater control is not same as that of grid columns as depicted in the attachment , could you please suggest that width of both of them should remain same
AlignmentIssue.docx
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:satmisha
Comment Utility
Provided below is the code I have been using where getting issue of alignment:

 <Data:GridView ID="GridView1" runat="server" AllowSorting="True"
                AutoGenerateColumns="False" CellPadding="4" EnabledDuringCallBack="False" ForeColor="#333333"
                GridLines="None" PageSize="1" Font-Overline="False" Font-Size="X-Small"  AutoUpdateAfterCallBack="True" Width="98%"  CssClass="scroll-grid"
                UpdateAfterCallBack="True" PreCallBackFunction="disablegrid" PostCallBackFunction="enablegrid"  >
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <EmptyDataTemplate>
                    <anthem:Label ID="lblEmpty" runat="server" Text="No Locations found"></anthem:Label>
                </EmptyDataTemplate>
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
                <EditRowStyle BackColor="#2461BF" />
                <PagerStyle BackColor="#2461BF" ForeColor="White"  HorizontalAlign="Center" />
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:TemplateField ShowHeader="False">
                        <ItemTemplate>
                            <anthem:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit1" CommandArgument="<%#                         ((GridViewRow) Container).RowIndex %>"
                                PostCallBackFunction="hidewait" EnableCallBack="True" EnabledDuringCallBack="False">Edit</anthem:LinkButton>&nbsp;
                            <anthem:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Remove"
                                PostCallBackFunction="
                                hidewait" EnableCallBack="False" EnabledDuringCallBack="False">Remove</anthem:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" />
                <RowStyle BackColor="#EFF3FB"  />
            </Data:GridView>
0
 

Author Comment

by:satmisha
Comment Utility
Experts could you please suggest ?
0
 
LVL 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
Comment Utility
make both 100%.
0
 

Author Closing Comment

by:satmisha
Comment Utility
Awesome man. Thank you so much.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now