Question

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>
Was it helpful?

Solution

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>

OTHER TIPS

use this line in your templatefield.

ItemStyle-HorizontalAlign="Right"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top