tags:

views:

264

answers:

1

a) As far as I know, GridView’s RowStyle-HorizontalAlign property should overwrite CSS’s text-align property, and thus text inside GridView's cells should be located on the left side of the cells, but is instead moved to the right side. Why is that?

b) Similarly, RowStyle-Font-Bold should overwrite CSS’s font-weight property and thus fonts shouldn’t be in bold. But again, CSS’s property overwrites RowStyle’s Font-Bold property. Why?

<div id="someClass">            
      <asp:GridView ID="gvwShowUsers"  runat="server" >
          <RowStyle BackColor="#FFFBD6" ForeColor="#333333" Font-Bold="false" 
               HorizontalAlign="Left" />
          <Columns>
             <asp:BoundField DataField="UserName" HeaderText="UserName"  />
          </Columns>
      </asp:GridView>
</div>

CSS file:

#someClass td
{
  font-weight:bolder;
  text-align:right;
}

thanx


EDIT:

A workaround would be to apply the style to each field instead (e.g. ItemStyle-HorizontalAlign)

I tried with applying ItemStyle to GridView’s field:

   <div id="someClass">            
      <asp:GridView ID="gvwShowUsers"  runat="server" >
         <RowStyle Font-Bold="false" HorizontalAlign="Left" />
          <Columns>
             <asp:BoundField DataField="UserName" HeaderText="UserName">
                <ItemStyle HorizontalAlign="Left" Font-Bold="false" />
             </asp:BoundField>
          </Columns>
      </asp:GridView>
   </div>

But since even after applying ItemStyle the page still displayed text on the right side of the cells, I've decided to check the source code of a html page sent to the user, and as it turns out both <tr> and <td> elements have Align property set to left, so...totally confused!

Here is the source code of a html page:

<table id="GridView1" style="font-weight:normal;">
   <tr align="center" style=" font-weight:bold;">
       <th scope="col">UserName</th>
   </tr>
       <tr align="right" valign="bottom" style="font-weight:normal;">
       <td align="right" style="font-weight:normal;"> Nancy</td>
   </tr>
</table>
+1  A: 

If the style is being added to the <tr> element, the style in the CSS file will win because the #someClass td selector is more specific.

A workaround would be to apply the style to each field instead (e.g. ItemStyle-HorizontalAlign).

Frank Schmitt
"If the style is being added to the <tr> element, the style in the CSS file will win because the #someClass td selector is more specific." Don't inline styles styles always win ( I'm assuming GridView.RowStyle-HorizontalAlign is inline style? )?"A workaround would be to apply the style to each field instead (e.g. ItemStyle-HorizontalAlign)." I did try that, but to no effect
AspOnMyNet
To paraphrase Jerry MacGuire, show me the HTML :). Inline styles win when applied to the *same element* as a CSS rule, but not when they are applied to a parent element. Just because you've made your text red in your body tag's style attribute, doesn't mean you can't have a green paragraph specified with a CSS rule.
Frank Schmitt
hi,I've edited my initial post in a response to your reply...in case you are willing to help me some more
AspOnMyNet