Rohan
Rohan

Reputation: 2935

how to give the color to first column of the grid?

i want to give color to the first coloumn as same as header of the grid.

this is the image of original grid which i want. this is the image of original grid which i want..

this is the image of my which is displaying now

this is the image of my which is displaying now..

and this grid is created dynamically and all data are filld from server. so i want is to give color to only first coloumn ( not all coloumn , as shown in image)of grid at runtime

Upvotes: 0

Views: 3037

Answers (4)

user2641463
user2641463

Reputation:

GridView1.Columns[0].ItemStyle.BackColor = System.Drawing.Color.Red;

post this after you bind grid data.ie after

GridView1.DataBind();

Upvotes: 1

Vinod
Vinod

Reputation: 4892

Try this:

GridView1.Columns[0].ItemStyle.BackColor = System.Drawing.Color.Orange;

Upvotes: 1

Neha
Neha

Reputation: 2965

Add itemstyle to your first template field

<HeaderStyle BackColor="#FEFF01" HorizontalAlign="Center"  />
 <ItemStyle BackColor="#FEFF01" Font-Bold="True" HorizontalAlign="Center" />

EDIT:

see here is my grid view

<asp:GridView ID="GridViewOrganizationShareFee" runat="server" 
                        AutoGenerateColumns="False" BackColor="White">
                         <HeaderStyle BackColor="#FFC000" Font-Bold="True" ForeColor="Black" Height="45px" HorizontalAlign="Center"  />
                         <RowStyle ForeColor="Black" BackColor="#FFFDFF" Font-Bold="true" />                      
                    <Columns>                  
                     <asp:TemplateField HeaderText="Organization">
                            <ItemTemplate>
                                <asp:Label ID="LabelOrganizationName" runat="server" Text='<%#Eval("OrganizationID").ToString()=="0"?"n/a":Eval("Name") %>'></asp:Label>
                            </ItemTemplate>                           
                            <HeaderStyle BackColor="#FEFF01" HorizontalAlign="Center"  />
                            <ItemStyle BackColor="#FEFF01" Font-Bold="True" HorizontalAlign="Center" />
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Fee Type">
                             <ItemTemplate>
                               <asp:Image ID="ImageDollor" runat="server" ImageUrl="~/Images/Icons/dollor.png" Visible='<%#Eval("DojoEventPaymentType").ToString().ToLower()=="a"?true:false %>' />
                                 <asp:Image ID="ImagePercent" runat="server" ImageUrl="~/Images/Icons/percent.png" Visible='<%#Eval("DojoEventPaymentType").ToString().ToLower()=="p"?true:false %>' />            </ItemTemplate><ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>

                    </Columns>
                    </asp:GridView>    

Upvotes: 4

tobias86
tobias86

Reputation: 5029

You could do this using simple CSS

table tr td:first-child
{
    background-color: #FACF7B;
}

EDIT: This rule will apply to ALL tables though. You can change it to only apply to certain tables, e.g.:

.myTable tr td:first-child /* all tables with class="myTable" */
{
    background-color: #FACF7B;
}

#myTable tr td:first-child /* tables with id="myTable" */
{
    background-color: #FACF7B;
}

Upvotes: 4

Related Questions