如何给Repeater内的每个GridView赋予不同的颜色? [英] How to give each GridView inside the Repeater a different color?

查看:102
本文介绍了如何给Repeater内的每个GridView赋予不同的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个转发器和转发器内部的三个GridViews.每个GridView的列都与其他列不同,因为我有一个存储过程,并且每个GridView都具有基于中继器内部HiddenField值的endend列.
现在,我想为每个GridView提供不同的颜色,尤其是对于每个GridView中不同的列,但是我不知道该怎么做.

我的代码:

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:

<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">

推荐答案

ConnectionStrings:testConnectionString%>" SelectCommandType = " SelectCommand = " kbiReport" FilterExpression = " > < SelectParameters> <%-ControlParameter 链接到上面的HiddenField,以基于不同的值生成不同的GridView 的GroupID-%> < asp:ControlParameter ControlID = " Name = " PropertyName = " /> </ SelectParameters > < asp:GridView ID = " runat = " AllowSorting = " CellPadding = " DataSourceID = " CssClass = " AlternatingRowStyle-CssClass = " RowStyle-Horizo​​ntalAlign = " > < alternatingrowstyle backcolor = " forecolor = " #284775"/> <列> < asp:CommandField ShowSelectButton = " /> </ > </ itemtemplate > < asp:SqlDataSource ID = " runat = " 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 = " ">> /span>
ConnectionStrings:testConnectionString %>" SelectCommand="SELECT DISTINCT GroupID FROM courses">


设置gridview.Background属性以设置repeater1_ItemDataBound事件中您选择的颜色,使用findcontrol()方法在repater行中找到gridview,甚至可以检查itemIndex属性用于标识转发器的行索引,请注意!!检查Item/Alternate Item/Header/Footer的ItmeType,仅在相关的内部设置

如果有帮助,请标记为答案..
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..


这篇关于如何给Repeater内的每个GridView赋予不同的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆