1

I have a TextBox in a GridView ItemTemplate. I added css style to it using CssClass="txtboxAlignRight". but when i run my page, style is not applied.

I have an another TextBox in a GridView FooterTemplate. i added this style to that TextBox also. it's working properly. but TextBox in GridView ItemTemplate is not applying this style.

How can i solve this ?

Css

.txtboxAlignRight
{    
    text-align: right;
    border: 1px solid #ccc;
    border-radius: 4px;
    -moz-border-radius: 4px;
    -webkit-border-radius: 4px;         

}

aspx page

<ItemTemplate>
    <asp:TextBox ID="txt_cc" Width="150" runat="server" Text='<%# Bind("COUNT") %>'
        CssClass="txtboxAlignRight"></asp:TextBox>
</ItemTemplate>
5
  • Can you provide both the css class you are using and a little snippet of the page where that is declared? that might help to see what's wrong :) Commented Jun 25, 2013 at 10:50
  • @CarlosB there are no errors with declaration or css class. because it is working properly in FooterTemplate. Commented Jun 25, 2013 at 10:55
  • so none of the style is applied when the page is rendered. Ok did you define any gridview event that might alter the rows somehow? like onRowDataBound? Commented Jun 25, 2013 at 11:01
  • @CarlosB no. no any gridview event. Commented Jun 26, 2013 at 3:13
  • The only thing i can remember at this point is the rendering process of the gridview eliminating your css definition (not translating to class="txtboxAlignRight"), to debug this try and check the html present on the browser (but frankly i'm a bit out of ideas). Commented Jun 26, 2013 at 11:09

2 Answers 2

1

I have added below code in to my css file.

input[type="text"]
{   
    border: 1px solid #ccc;
    border-radius: 4px;
    -moz-border-radius: 4px;
    -webkit-border-radius: 4px; 
}

This apply style to all text boxes in my page. then i added Style="text-align: right" to TextBox in my ItemTemplate.

<ItemTemplate>
    <asp:TextBox ID="txt_cc" Width="150" runat="server" Text='<%# Bind("COUNT") %>'
        Style="text-align: right"></asp:TextBox>
</ItemTemplate>
Sign up to request clarification or add additional context in comments.

Comments

0

use this line in your templatefield.

ItemStyle-HorizontalAlign="Right"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.