2010-10-18 27 views
16

Tôi có một GridView có thể chỉnh sửa được. Vấn đề của tôi là khi tôi nhấp vào Chỉnh sửa, hộp văn bản quá nhỏ (cột File Name). Nó không đủ lớn để hiển thị nội dung của nó, và nó không rộng bằng phần còn lại của cột.Làm cách nào để đặt chiều rộng của hộp văn bản khi chỉnh sửa hàng trong GridView?

Làm cách nào để làm cho hộp văn bản đó rộng hơn?


Dưới đây là các mã ASP:

<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> 

Có C# mã đằng sau này để cập nhật dữ liệu, và làm việc tốt. Tôi hy vọng các giải pháp này là trong ASP, nhưng nếu giải pháp đòi hỏi một số mã C#, đó là OK với tôi.

Trả lời

8

này nên làm việc:

<asp:BoundField DataField="Name" HeaderText="File Name" /> 
    <controlstyle Width="200"> 
    </controlstyle> 
</asp:BoundField> 
14

Bạn có thể áp dụng một lớp CSS để kiểm soát như thế này:

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

Và sau đó thiết lập của bạn width trong StyleSheet bạn:

input.wide { width: 100px; } 
1

Bạn có thể covert hộp văn bản/hộp thả xuống thành một Templatefiled bằng cách vào Edit Filed Option. Sau đó đi tới chỉnh sửa mẫu, xác định chiều rộng/chiều cao của hộp.

4

Bạn cần phải thiết lập các ItemStyle-Width cho cột và ControlStyle-Width cho sự kiểm soát bên trong cột:

<asp:BoundField DataField="Name" HeaderText="File Name" /> 
    <ItemStyle Width="200px" /> 
    <ControlStyle Width="100%" /> 
</asp:BoundField> 
Các vấn đề liên quan