• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6863
  • Last Modified:

GridView with ItemTemplate TextBox Right Align

Hi,

I'm trying to right align the textbox which is inside the GridView control. Here is the code:
         <asp:TemplateField HeaderText="Remaining Qty" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="10">
            <ItemTemplate>
                <asp:TextBox runat="server" ID="TextBoxInvRemQty" Text='<%# String.Format("{0:###,##0}", Convert.ToDouble(Eval("InvQty"))) %>' 
                    BorderStyle="none" BackColor="transparent" Width="80px" ReadOnly="True" TabIndex="-1"></asp:TextBox>
            </ItemTemplate>

Open in new window


Can anyone help me on how to get the textbox right-aligned when there is lengthy number displayed for e.g: 2220 or 22220 or 22000000.
0
learntechnology
Asked:
learntechnology
  • 2
2 Solutions
 
CodeCruiserCommented:
You mean the text inside textbox?

Set css property

style="text-align: right"
0
 
informaniacCommented:
Please try this.
<asp:TextBox onkeydown="javascript:setAlignment();" ID="rightAlignedTextBox" runat="server"></asp:TextBox>

<script type="text/javascript" language="javascript">
        function setAlignment(txtBox) {
            if (txtBox.value.length > 5) {
                txtBox.style.textAlign = "right";
            }
            else{
                txtBox.style.textAlign = "left";
            }
        }
    </script>

Open in new window

0
 
learntechnologyAuthor Commented:
Hi All,

Thanks for your suggestions. I have modified my code by adding style, please see the code below:

         <asp:TemplateField HeaderText="Remaining Qty" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="10">
            <ItemTemplate>
                <asp:TextBox runat="server" ID="TextBoxInvRemQty" Text='<%# String.Format("{0:###,##0}", Convert.ToDouble(Eval("InvQty"))) %>' 
                    BorderStyle="none" BackColor="transparent" Width="80px" ReadOnly="True" TabIndex="-1" [b]style="text-align:right;[/b]"></asp:TextBox>
            </ItemTemplate>
           
        </asp:TemplateField>

Open in new window

0
 
learntechnologyAuthor Commented:
I have tried in multiple ways and added style inside the item template textbox.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now