【问题标题】:Column width on Gridview not wrapping in edit modeGridview 上的列宽未在编辑模式下换行
【发布时间】:2014-01-29 05:54:04
【问题描述】:

问题:Gridview 上的列宽未在编辑模式下换行

“预览”上的标题在适合 1000 像素宽的整齐列中显示标题文本。一旦我按下编辑,表格就会扩大到这个大小。

如何在编辑视图中强制设置表格的最大大小?

代码:CSS / VB.net

.aspx 页面

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="1000px"
    AllowPaging="True" AllowSorting="True" CssClass="mGrid" PagerStyle-CssClass="pgr"
    EmptyDataText="There are no data records to display - Please change your search."
    DataKeyNames="EmployeeID" AlternatingRowStyle-CssClass="alt" DataSourceID="SqlDataSource1"
    EnableViewState="true" EnableModelValidation="True" >
    <AlternatingRowStyle CssClass="alt"  />

示例字段:

<asp:TemplateField HeaderText="Login Name" SortExpression="UserName">
 <ItemTemplate>                   
  <%# Eval("UserName") %>
 </ItemTemplate>
 <EditItemTemplate>
   <asp:TextBox ID="txtUserName" runat="server" Text='<%# Bind("UserName") %>'/>
 </EditItemTemplate>
</asp:TemplateField>

CSS(还有更多,但我相信这是我需要看的地方)

在我看来,100% 相当于网格中所指的 1000px 的 100%,因为在我点击编辑之前这是有效的。

.gridview { 
        font-family:"arial"; 
        background-color:#002649; 
        width: 100%; 
        font-size: small; 
        color: #658654;       
        table-layout:fixed;

} 

【问题讨论】:

  • 您还必须在 edititemtemplate 中的文本框上指定宽度。是文本框导致了这种情况,因为它们的默认宽度大于表格上的列宽。

标签: html asp.net css gridview


【解决方案1】:

在 ItemStyle 中设置网格视图的列宽以及 TextBox 的宽度。例如

<asp:TemplateField HeaderText="Login Name" SortExpression="UserName">
     <ItemTemplate>                   
          <%# Eval("UserName") %>
     </ItemTemplate>
     <EditItemTemplate>
          <asp:TextBox ID="txtUserName" runat="server" width="200px" Text='<%# Bind("UserName") %>'/>
     </EditItemTemplate>
     <ItemStyle width="200px"> </ItemStyle>
</asp:TemplateField>

【讨论】:

  • 我想你可能会说 :-( 我可以把 textbox 和 itemstyle 的宽度作为一件事放在 CSS 中吗?(这样我可以标准化大部分列)
  • 如果你从 css 修复大小,那么它将修复所有列和文本框宽度的大小。如果你没问题,那么我可以举个例子。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-26
  • 1970-01-01
  • 2012-01-16
  • 2013-01-30
  • 2020-02-13
  • 1970-01-01
相关资源
最近更新 更多