Link to home
Start Free TrialLog in
Avatar of learntechnology
learntechnologyFlag for United States of America

asked on

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.
SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of learntechnology

ASKER

I have tried in multiple ways and added style inside the item template textbox.