【问题标题】:How to set the width of a gridview's command column in edit mode?如何在编辑模式下设置gridview命令列的宽度?
【发布时间】:2012-10-19 13:59:36
【问题描述】:

我扩展了一个gridview,以便它可以插入新行。当 gridview 插入新行时,我希望命令链接按钮显示 Add(而不是 Update)。所以我将命令列从数据绑定转换为模板字段。我已将列的宽度设置为 100px,以便它包含两个 LinkBut​​ton。

<asp:TemplateField ShowHeader="False" ItemStyle-Width = "100px">
</asp:TemplateField>

但是,当行进入编辑模式时,大小不是 100px。链接按钮不再彼此相邻,而是一个在另一个顶部。即使在编辑模式下,如何将命令列的宽度保持为 100px?

感谢您的帮助

【问题讨论】:

  • 在 TelplateField 属性编辑器中将 wrap 属性修改为 false 已解决部分问题。两个 LinkBut​​ton 不再是一个在另一个之上。现在,即使在 EDIT 模式下,它们也彼此相邻。但是我仍然无法在编辑模式下将列的宽度设置为 100px。

标签: asp.net gridview


【解决方案1】:

这并不优雅,但您可以使用 GridView 的 OnRowDataBound 事件来强制每个单元格的宽度:

ASP.NET

<asp:GridView ID="gv" runat="server" OnRowDataBound="gv_RowDataBound"...

C#

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
    // regardless of edit mode or DataControlRowType
    e.Row.Cells[0].Width = 100;
}

假设您的 TemplateField 在您的 GridView 中的列索引为 0。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-29
    • 2011-05-07
    • 2014-01-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2017-11-26
    相关资源
    最近更新 更多