如何在编辑模式下设置gridview命令列的宽度?

时间:2022-03-04 21:44:59

I've extended a gridview so that it can insert new row. When the gridview is inserting a new row, I want the command linkbutton to display Add (instead of Update). So I converts the command column from databound to template field. I've set the width of the column to 100px so that it contains both LinkButton.

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

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

However, when the row enter in edit mode, the size is not 100px. Linkbuttons are not next to each other anymore but one on the top of the other. How do I keep the width of the command column to 100px even in edit mode?

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

Thanks for helping

谢谢你的帮助

1 个解决方案

#1


0  

It's not elegant, but you could force the width for every cell using your GridView's OnRowDataBound event:

它不优雅,但您可以使用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;
}

Assuming your TemplateField has a column index of 0 in your GridView.

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

#1


0  

It's not elegant, but you could force the width for every cell using your GridView's OnRowDataBound event:

它不优雅,但您可以使用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;
}

Assuming your TemplateField has a column index of 0 in your GridView.

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