Align text in GridViewTemplate TextBox

I need to align the text to the right in the TextBox , which is in the GridView TemplateField

This is HTML TemplateField :

 <asp:TemplateField HeaderText="Description"> <ItemTemplate> <div style="text-align: right;"> <asp:TextBox ID="txtDeductAmount" runat="server" Text="" BorderWidth="1px"></asp:TextBox> </div> </ItemTemplate> <ItemStyle Width="80px" HorizontalAlign="Right" /> </asp:TemplateField> 

It is still aligned on the left side. How to make text align right?

NOTE. <ItemStyle Width="80px" HorizontalAlign="Right" /> correctly aligns the text field on the right side.

+4
source share
4 answers

These options do not change the text input field, but the table tags are aligned.

To change how text is entered, add a class to it.

 .AlgRgh { text-align:right; font-family:Verdana, Arial, Helvetica, sans-serif; } 

and use CssClass="AlgRgh" to control

 <asp:TextBox ID="txtDeductAmount" runat="server" Text="" BorderWidth="1px" CssClass="AlgRgh" /> 
+2
source

Or that:

  <asp:TemplateField HeaderText = "Bank" SortExpression="BankID"> <ItemStyle HorizontalAlign="Right"></ItemStyle> <ItemTemplate> <asp:Label ID="BankIDLabel" runat="server" Text='<%# Bind("BankID") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> 
+4
source

Hannington Mambo answers the job flawlessly, the faster:

 <asp:TemplateField HeaderText = "Bank" SortExpression="BankID"> <ItemStyle HorizontalAlign="Right"></ItemStyle> <ItemTemplate> <asp:Label ID="BankIDLabel" runat="server" Text='<%# Bind("BankID") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> 
0
source

When setting text box values ​​inside a GridView you can use this code in .cs :

((TextBox)GridView1.Rows[Index of the grid].FindControl("txtName")).Style.Add("text-align", "right");

0
source

Source: https://habr.com/ru/post/1397006/


All Articles