How to Style Template field in Grid View (aspx page and CSS attached)


Tags: asp.net,css,gridview,styles

Problem :

i am trying to style my second column "mentor name" as i used css it give style to whole Grid i also tried "control styl css class = (some other css file)" and "item styl horizontal align=right" and also change property align = right by using # in css file but template field do not allow "id" to implement css my .aspx page and css ar below,

.mGrid {   
    width: 100%;   
    background-color: #fff;   
    margin: 0px 0 0px 0;   
    border:  0px #525252;   

}  

.mGrid table
{
    border:0px;
}

.mGrid td {   
    padding: 2px;   
    border-width:  0px ;   
    background-color:#3A3F3E;
    color: #fff;   
    text-align:left;
}  
td#Mname  {   
    text-align:left;
}  
.mGrid th {   
    padding: 4px 2px;   
    color: #fff;  
    background-color:#3A3F3E; 
    border-width: 0px ;   
    font-size: 0.9em;   
    text-align:center;
}  



<asp:GridView  Width="300px" ID="GridView1" runat="server" AutoGenerateColumns="False"
                    Font-Size="10pt" OnRowCreated="GridView1_RowCreated" CssClass="mGrid">
                    <Columns>
                        <asp:BoundField DataField="mentor_id" HeaderText="Image" />
                        <asp:TemplateField HeaderText="Image">
                            <ItemTemplate>
                                <asp:Image ID="Image2" runat="server" ImageUrl="~/images/small_image.png" />
                            </ItemTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField  HeaderText="Mentor Name">
                        <ItemTemplate>
                            <asp:Label ID="Label1" Text='<%#Eval("mentor_FirstName")+ "</br> " + "<b>Experience: </b>"+Eval("mentor_experience") %> ' runat="server"></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>

hopes for your suggestions thanks in advance



Solution :

use td+td it will be applied to the Second td of the grid.

.mGrid td+td {   
     text-align:left !important;
}
.mGrid td+td+td {   
     text-align:left !important;
}

Here is a good post on this. styling the last td in a table with css


    CSS Howto..

    How to hide element that is currently mousedover and shown via :hover css pseudo class via jQuery

    How to position bottom of div above top of its container

    How does tablesort.js create the sort indicator arrows

    How to show Div after a Specific time of page load?

    How can I make buttons flash different background colors when clicked/

    How can I place multiple spans in the same line?

    How To Apply jQuery CSS Selector

    How do I make a absolute positioned div have a width equal to it's parent minus some margin

    How to make Gravity Forms Responsive (left/right )?

    How to print text between css selectors in golang using html package?

    How to get css property of a DOM element server-side?

    Should be Simple: How to preserve data on a page of basic javascript/css/html when going to another page

    How can I use True Type Collection (.ttc) in JavaFX?

    how to make CSS animation to play every 10 seconds

    HTML/CSS - How to get label inside form to animate?

    How to set link color inside GridView cell

    I want to make semi-identical manu like the one on this page - how? [closed]

    Ruby on rails dropdown