调整GridView的编辑文本框大小 [英] Adjust GridView EDIT textbox size

查看:972
本文介绍了调整GridView的编辑文本框大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VS2005 C#

I am using VS2005 C#

我有一个GridView和我已经启用了行编辑。

I have a GridView and I have enabled row editing.

不过,我有一些列将有较大的投入,如的注释的列,其中将包含更多的单词。

However, I have some columns which will have a larger input, such as Comments column, which will contain more words.

有没有办法来调整文本框的大小?

Is there a way to adjust the textbox sizes?

推荐答案

如果你想在宽度控制的的高度,以及其他属性,您可以在GridView的RowDataBound事件中引用的文本框和设置其高度和宽度以及的TextMode设置为多行

If you want control over width and height, as well as other properties, you can reference the TextBox in your GridView's RowDataBound event and set its height and width as well as setting the TextMode to MultiLine:

protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Edit)
    {
        // Comments
        TextBox comments = (TextBox)e.Row.Cells[column_index].Controls[control_index];
        comments.TextMode = TextBoxMode.MultiLine;
        comments.Height = 100;
        comments.Width = 400;
    }
}

确保你通过检查的RowState或引用EditIndex编辑一行,并适当设置与Column_Index和control_index。对于绑定列,控制指标通常是0。

Ensure you're referencing the edit row by checking the RowState or EditIndex, and set your column_index and control_index appropriately. For BoundFields, the control index will typically be 0.

这篇关于调整GridView的编辑文本框大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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