How to fix width for each column in gridview?

How can I fix the width for each column in a gridview. My GridView continues to expand along with the data in the cell. I need her to jump to a new line when she reaches the right side of the cell. This is my code in the .aspx file:

<asp:GridView ID="GridView1" runat="server" 
AutoGenerateColumns="False" DataKeyNames="Emp_ID" DataSourceID="LinqDataSource1"
AllowPaging="True"  AllowSorting="True" Width="900px" HorizontalAlign="Center" >                        
           <Columns>
               <asp:BoundField DataField="Emp_ID" HeaderText="ID" 
        InsertVisible="False" ReadOnly="True" SortExpression="Emp_ID"/>
               <asp:BoundField DataField="Emp_Username" 
        HeaderText="Username" SortExpression="Emp_Username" />
               <asp:BoundField DataField="Emp_Password" 
        HeaderText="Password" SortExpression="Emp_Password" />
               <asp:BoundField DataField="Emp_Name" 
        HeaderText="ชื่อพนักงาน" SortExpression="Emp_Name" />
               <asp:BoundField DataField="Emp_Address" 
        HeaderText="ที่อยู่" SortExpression="Emp_Address" />
               <asp:BoundField DataField="Emp_Tel" 
        HeaderText="เบอร์โทรศัพท์" SortExpression="Emp_Tel" />
               <asp:TemplateField HeaderText="รูปพนักงาน" SortExpression="Emp_Picture">
                    <EditItemTemplate>
                         <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Emp_Picture") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Image ID="Image2" runat="server" Height="70px" 
                                        ImageUrl='<%# Eval("Emp_Picture", "{0}") %>' Width="50px" />
                    </ItemTemplate>
              </asp:TemplateField>
              <asp:BoundField DataField="Status" HeaderText="สถานะ" 
        SortExpression="Status" />
              <asp:HyperLinkField DataNavigateUrlFields="Emp_ID" 
                                DataNavigateUrlFormatString="AdminUpdate.aspx?Emp_ID={0}" Text="Edit" />
              <asp:TemplateField>
                   <HeaderTemplate>
                       <asp:CheckBox ID="ChkSelectAll" runat="server" 
                AutoPostBack="True" oncheckedchanged="ChkSelectAll_CheckedChanged"  />
                   </HeaderTemplate>
                   <ItemTemplate>
                       <asp:CheckBox ID="Chk" runat="server" AutoPostBack="True" oncheckedchanged="Chk_CheckedChanged" />
                   </ItemTemplate>
               </asp:TemplateField>
           </Columns>
</asp:GridView>

Here is my design:

Imgur

As you can see, the first 4 columns have no problems with this until the 5th column. It continues to expand because all GridViews go beyond the page.

+4
source share
5 answers

The wrapper is word-based so that no single word is split into two lines.

Thus, this will not work for you if your data has a long string without spaces.

, , .

we show only that long string which can be accommodated in column and then add "..." (only if string is more than what is showing) and then add a tooltip to show the full string. , , , .

,

+1

itemstyle . .

<asp:BoundField DataField="Emp_Address" 
    HeaderText="ที่อยู่" SortExpression="Emp_Address">
   <ItemStyle Width="200px" HorizontalAlign="Left" />
</asp:BoundField>
+3

RowStyle-Wrap GridView True.

0

You can use ItemStyle-Widthto correct the column width, but if you enter characters that cannot be enclosed in a given width (as seen in your image), the column will expand according to the inputs so that you can use the RowStyle-Wrapgridview property

<asp:GridView ID="grdVwtrial" runat="server" RowStyle-Wrap="true">
0
source

RowStyle-Wrap==trueshould work, I think. For more clarification see this: http://forums.asp.net/t/1263769.aspx

-1
source

All Articles