ASP.net How do I get the width of an input box and a GridView column to match

Murray Brown
Murray Brown used Ask the Experts™
on
Hi. In my ASP.net web app I am trying to get the width of an input box and a GridView template column. The two do not look the same size.

What might I be doing wrong. The markup code for them is shown below

<input id="TotalWeight2" runat="server" type="text" placeholder="To"   class="auto-style8" style="font-size: medium; width:75px"/>

Open in new window


                    <asp:TemplateField HeaderText="Total Weight" SortExpression="Total Weight" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="true" >
                            <ItemTemplate>
                            <asp:Label ID="lblTotalWeight" runat="server" Text='<%# Bind("[Total Weight]")%>' Width="75" ></asp:Label>
                            </ItemTemplate> 
                    </asp:TemplateField>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Commented:
what if changing to something like this?

<asp:Label ID="lblTotalWeight" runat="server" Text='<%# Bind("[Total Weight]")%>' Width="100%" ></asp:Label>
Ryan ChongSoftware Team Lead

Commented:
similar for your text input, what if applied width=100% ?
Murray BrownASP.net/VSTO Developer

Author

Commented:
Hi Ryan. Won't that stretch it across the whole screen. Here is an image showing the white input boxes compared
to my GridView template columns. When I used textboxes instead of <input> boxes things aligned well by making each
box the same width as the column

1
Software Team Lead
Commented:
isn't that Textbox control in ASP.NET will generate the HTML Input element as well?

<input id="TotalWeight2" runat="server" type="text" placeholder="To"   class="auto-style8" style="font-size: medium; width:75px"/>

have you try to amend the class as well as the style part? It could affecting how your element being presented.

have you compare what's the HTML output generated that using TextBox control against the "input" element?
Murray BrownASP.net/VSTO Developer

Author

Commented:
Thanks very much. Sorry about late acceptance

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial