Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a repeater and three GridViews inside the repeater. Each GridView has different columns than the others since I have a storedprocedure and each GridView has differend columns based on the value of the HiddenField inside the repeater.

Now I would like to give each GridView a different color especially for the columns that are different in each GridView, but I don't know how to do that.

My code:
C#
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
            <itemtemplate>
                
                <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("GroupID")%>' />
                
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:testConnectionString %>" 
                                    SelectCommandType="StoredProcedure" SelectCommand="kbiReport"
                                    FilterExpression="[Division] like '{0}%' and [Organization] like '{1}%'">
                        

                    <SelectParameters>
                        <%--ControlParameter is linked to the HiddenField above to generate different GridView based on different values 
                            of GroupID--%>
                        <asp:ControlParameter ControlID="HiddenField1" Name="GroupID" PropertyName="Value" />
                    </SelectParameters>
                

                <asp:GridView ID="GridView1" runat="server" 
                                AllowSorting="True" 
                                CellPadding="3" 
                                DataSourceID="SqlDataSource1" 
                                CssClass="mGrid"
                                AlternatingRowStyle-CssClass="alt" 
                                RowStyle-HorizontalAlign="Center">
                    <alternatingrowstyle backcolor="White" forecolor="#284775" />
                    <columns>
                        <asp:CommandField ShowSelectButton="True" />
                    </columns>
                
                

            </itemtemplate>
        
        
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                           ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
                           SelectCommand="SELECT DISTINCT GroupID FROM courses">
Posted
Updated 28-Oct-11 20:49pm
v2
Comments
hzawary 29-Oct-11 7:02am    
I think that you can use the "Alternative" color property (option in your GridView or like it).

1 solution

set gridview.Background Property to set colour of your choice inside repeater1_ItemDataBound event, use findcontrol() method to find gridview inside repater row, you can even check the itemIndex property to identify the row index of repeater, beware!! check the ItmeType for Item/Alternative Item/Header/Footer, set inside only your relavant

mark as answer if helps you..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900