2012-01-12 35 views
0

我想給第一個顏色的顏色與網格的標題相同。如何給網格的第一列添加顏色?

這是我想要的原始網格的圖像。 this is the image of original grid which i want..

這是我這是目前顯示

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

的形象,該網格是動態創建和所有的數據從服務器filld。所以我想在運行時給皮膚上色電網僅第一coloumn(不是所有coloumn,如圖片所示)

回答

4

你可以做到這一點使用簡單的CSS

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

編輯:此規則適用於所有表格。你可以將其更改爲只適用於特定表,例如:

.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; 
} 
4

添加itemstyle你的第一個模板字段

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

編輯:

在這裏看到的是我的網格視圖

<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>  
+0

你的第一個模板的itemstyle做的正是你希望它不要把在整個列 – Neha 2012-01-12 10:41:11

+1

看我的網格之後,你有一些想法。 – Neha 2012-01-12 10:45:00

+0

您也可以在網格的數據綁定事件中設置此 – Neha 2012-01-12 10:59:02

1

試試這個:

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

這不支持vb。 – Rohan 2012-01-12 12:01:06

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

交這個你綁定網格data.ie後

GridView1.DataBind();