html - 模板字段宽度在 asp.net 的 GridView 中没有增加

标签 html css asp.net gridview templatefield

我使用了一个模板字段来添加编辑、更新、删除和取消图像图标。但是编辑和删除模板字段宽度很小,由于宽度较小,这两张图片在垂直方向上显示为一张。如何增加模板字段的宽度,使其可以在一行中水平显示两个图像

  <asp:TemplateField>

     <ItemStyle Width="80px" />
<HeaderStyle  Width="80px" />
 <FooterStyle Width="80px" /> 
        <ItemTemplate>
        <asp:ImageButton ID="btnEdit" runat="server" CommandName="Edit" ImageUrl="img/edit.png" ToolTip="Edit" />
        <asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" ImageUrl="img/delete.PNG" ToolTip="Delete" />
    </ItemTemplate>
    <EditItemTemplate>
        <asp:ImageButton ID="btnUpdate" runat="server" CommandName="Update" ImageUrl="img/icon-update.png" ToolTip="Update" Height="18px" Width="18px" />
        <asp:ImageButton ID="btnCancel" runat="server" CommandName="Cancel" ImageUrl="img/icon-Cancel.png" ToolTip="Cancel" CausesValidation="false" Height="16px" Width="16px" />
    </EditItemTemplate>
   </asp:TemplateField>

最佳答案

您可能需要将按钮包裹在一个 div 中,并使用 CSS 样式来设置宽度。

在您的样式表中定义一个选择器,如下所示:

.buttonColumnWidth
{
    width: 80px; /* change this value as required */
}

然后,对您的 Gridview 进行以下更改:

    <asp:TemplateField>

         <ItemStyle Width="80px" />
         <HeaderStyle  Width="80px" />
         <FooterStyle Width="80px" /> 
            <ItemTemplate>
            <div class="buttonColumnWidth">
                <asp:ImageButton ID="btnEdit" runat="server" CommandName="Edit" ImageUrl="img/edit.png" ToolTip="Edit" />
                <asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" ImageUrl="img/delete.PNG" ToolTip="Delete" />
            </div>
        </ItemTemplate>
        <EditItemTemplate>
            <div class="buttonColumnWidth">
                <asp:ImageButton ID="btnUpdate" runat="server" CommandName="Update" ImageUrl="img/icon-update.png" ToolTip="Update" Height="18px" Width="18px" />
                <asp:ImageButton ID="btnCancel" runat="server" CommandName="Cancel" ImageUrl="img/icon-Cancel.png" ToolTip="Cancel" CausesValidation="false" Height="16px" Width="16px" />
            </div>
        </EditItemTemplate>
   </asp:TemplateField>

关于html - 模板字段宽度在 asp.net 的 GridView 中没有增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34268467/

相关文章:

jquery - 从 JSON 文件创建联系人表

html - @media 宽度组件

具有不同名称的 JavaFX 2 类具有相同的 css 代码

css - 我有以下 'heading-font'

Javascript/Navbar 下拉菜单不适用于 Twitter Bootstrap

javascript - 站点向右加载,直到完成,然后居中

javascript - 从按钮调用函数不适用于使用 javascript 创建的 html

c# - FileUpload.HasFile 错误地返回 false

c# - 强制浏览器下载 PDF 文档而不是打开它

jquery - 在 jquery ajax 调用 wcf 服务上从 http 移动到 https 时出错