gymcode
gymcode

Reputation: 4623

Adjust GridView EDIT textbox size

I am using VS2005 C#

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?

Upvotes: 2

Views: 8728

Answers (3)

GBrookman
GBrookman

Reputation: 433

Brissles answer is correct but DataControlRowState can have multiple states ORed together so you may need to check for edit state like this:

(e.Row.RowState & DataControlRowState.Edit) != 0

Upvotes: 0

Amar Palsapure
Amar Palsapure

Reputation: 9680

Set the ItemStyle-Width and ControlStyle-Width, and if you want wrap the text use ItemStyle-Wrap.

Hope this helps.

Upvotes: 2

Brissles
Brissles

Reputation: 3891

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;
    }
}

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.

Upvotes: 4

Related Questions