views:

39

answers:

2

I've got a GridView that can be edited. My problem is that when I click Edit, the textbox is too small (the File Name column). It isn't large enough to display its contents, and it isn't as wide as the rest of the column.

How can I make that textbox wider?


Here's the ASP code:

<asp:GridView ID="FileGridView" runat="server" AllowPaging="True" OnPageIndexChanging="FileGridView_PageIndexChanging"
    CellPadding="1" CssClass="GridView"  GridLines="Horizontal"
    Width="100%" AutoGenerateColumns="false"
    AutoGenerateEditButton="true"
    OnRowCancelingEdit="GridView_RowCancelingEdit" OnRowEditing="GridView_RowEditing" OnRowUpdating="GridView_RowUpdating"
    >
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="File Name" />
        <asp:BoundField DataField="Length" HeaderText="Size" ReadOnly="true" />
        <asp:BoundField DataField="LastWriteTime" HeaderText="Last Modified" ReadOnly="true" />
    </Columns>
    <RowStyle CssClass="GridViewRow" />
    <EditRowStyle ForeColor="Black" CssClass="GridViewEditRow" />
    <SelectedRowStyle Font-Bold="True" CssClass="GridViewSelectedRow" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <HeaderStyle CssClass="GridViewHeader" ForeColor="White" />
    <AlternatingRowStyle CssClass="GridViewAlternatingRow" />
</asp:GridView>

There's C# code behind this to update the data, and that works just fine. I hope the solution to this is in the ASP, but if the solution requires some C# code, that's OK with me.

+2  A: 

This should work:

<asp:BoundField DataField="Name" HeaderText="File Name" />
    <itemstyle Width="200">
    </itemstyle>
</asp:BoundField>
Pieter
Thank you for the quick response. Unfortunately, this code didn't work. It made the whole column wider when not in edit mode, but when I click **Edit**, the width of that textbox is still the same size.
joshdick
And if you replace itemstyle with controlstyle? Does that help?
Pieter
Yes, that worked. Thank you!To get the width I wanted, I used `<ControlStyle Width="100%" />`
joshdick
A: 

you can apply a css class to the control like this

<asp:BoundField DataField="Name" HeaderText="File Name" 
    ControlStyle-CssClass="wide" />

and then set your width in your stylesheet

input.wide { width: 100px; }
lincolnk