Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
615 views
in Technique[技术] by (71.8m points)

c# - How to change GridView Header Style colour for selective columns

I am fairly new to asp.net webforms and I have the following code to generate a grid with two columns, I separated the columns using colours which I am able to do using e.Row.Cells[0].BackColor = Color.FromArgb(152, 251, 152);and for the second column e.Row.Cells[1].BackColor = Color.FromArgb(60, 179, 113) at the back end

what i am trying to achieve now is to colour the part of the GridView Header that is over the FirstColumn to the same colour as the first column and the second portion of the GridView Header that is over SecondCoumn to the same colour as the second column

Below is m y code

<asp:GridView ID="GridData" CssClass="Gridview" runat="server"
                                Width="100%" AutoGenerateColumns="False" OnRowDataBound="GridData_RowDataBound" ShowFooter="True">                               
                                <Columns>
                                    
                                    <asp:TemplateField ItemStyle-Width="120px" HeaderText="ColumnFirst" >
                                        <ItemTemplate>
                                            <asp:Label ID="lblLoanGiven" runat="server"></asp:Label>
                                        </ItemTemplate>

                                        <FooterTemplate>
                                            <asp:Label ID="lblTotalLoanGiven" runat="server"></asp:Label>
                                        </FooterTemplate>
                                    </asp:TemplateField>

                                    <asp:TemplateField ItemStyle-Width="120px" HeaderText="ColumnSecond">
                                        <ItemTemplate>
                                            <asp:Label ID="lblLoanGivenBalance" runat="server"></asp:Label>
                                        </ItemTemplate>

                                        <FooterTemplate>
                                            <asp:Label ID="lblTotalLoanGivenBalance" runat="server"></asp:Label>
                                        </FooterTemplate>
                                    </asp:TemplateField>

                                    
                           <PagerStyle BackColor="#3C8DBC" ForeColor="White" />
                                <HeaderStyle BackColor="#3C8DBC" ForeColor="White" />
                                <FooterStyle BackColor="#007C98" ForeColor="White" CssClass="footer-design" />
                            </asp:GridView>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
   GridData.HeaderRow.Cells[1].Style["background-color"] = "#3CB371"; 

Found the answer the above code colours my 2porions of the GridView headers


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...