如何解决在GridView的每一列的宽度? [英] How to fix the width for each column in GridView?

查看:168
本文介绍了如何解决在GridView的每一列的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解决在GridView的每一列的宽度。我的GridView保持沿与小区数据延伸。我需要它跳到新行,当它到达细胞的右侧。这是我在.aspx文件中的代码:

How can I fix the width for each column in GridView. My GridView keeps extend along with data in the cell. I need it to skip to new line when it reach the right side of the cell. This is my code in .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>

下面是我的设计视图:

< IMG SRC =http://i.imgur.com/hVXyaCH.pngALT =Imgur>

正如你所看到的,前4列没有这一问题直到5列它使扩展事业的所有的GridView延伸出页

As you can see, the first 4 columns has no problem with that until column 5. It keeps extend cause all GridView extend out of the page

推荐答案

包装完成基于这样的话任何一个词是不是在两条线断了。

Wrapping is done based on words so that any single word is not broken in two lines.

所以不会为你工作,如果你的数据有很长的字符串没有空间。

So won't work for you if your data has long string without space.

的问题是,你不能将你自己的空间,因为这可能会改变数据的意义。

The problem is that you can't insert spaces on your own because that may change the meaning of data.

而在网格显示我们只显示其可容纳列,然后添加一长串...(仅当字符串是比什么是显示出更多),然后添加一个工具提示显示完整的字符串。
这样的网格格式不会受到损害,如果用户希望他可以悬停在他的鼠标,看到整个字符串。

While showing in grid 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. That way the grid formatting is not compromised and if user wants he can hover his mouse and see the whole string.

希望这有助于

这篇关于如何解决在GridView的每一列的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆