Groups | Blog | Home
all groups > asp.net datagrid control > november 2005 >

asp.net datagrid control : DataGrid Edit TextBox


Aidal
11/3/2005 12:00:00 AM
Hi NG.

I'm having trouble controling the size of the textboxes that appear when the
user clicks the "edit" button for a row in my datagrid.
I know it can be done and I know it doesn't require much, but I just can't
seem to find out how to anyway.

If anyone could help me out with this little problem it would be much
appreciated :)

Thanks
/Aidal

S.M. Altaf [MVP]
11/3/2005 12:00:00 AM
We'll help you, but what is the problem? All I got was that you wanted =
to control the size of the textboxes, but you'll need to be more =
specific than that.



-------------------------------------------------------------------------=
-------
All that glitters has a high refractive index.=20
www.mendhak.com=20
[quoted text, click to view]
Hi NG.

I'm having trouble controling the size of the textboxes that appear =
when the=20
user clicks the "edit" button for a row in my datagrid.
I know it can be done and I know it doesn't require much, but I just =
can't=20
seem to find out how to anyway.

If anyone could help me out with this little problem it would be much=20
appreciated :)

Thanks
Aidal Theonly
11/4/2005 12:42:30 AM
Umm..Hmm that's it more or less - I'm not sure what else there is to
explain about it.

I want to be able to control the size of the textboxes that appear when
I click an 'Edit' button for a line in my datagrid.

Currently they are too long (the default width) resulting in the
datagrid becoming wider when a row is in edit mode and that doesn't look
good.

So I wan't to make sure that the width of the grid doesn't change once
an 'edit' button is clicked.

So that if this [----this width----] was the original size of a textbox
when a row is in edit mode, the new version could be [-this width-].

I hope this helps clearify what it is I mean.

/Aidal



alvinz_c
11/9/2005 1:41:02 AM
Hi, Aidal, you have two ways to do it. If you are using the BoundColumn, then
you can set the width of textbox in the ItemCreated event.

protected void dgrd_ItemCreated(Object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.EditItem)
{
TextBox txt = (TextBox)e.Item.Cells[X].Controls[0];
txt.Width = < the width you want it to be>;
}
}

Another way is set the TextBox's width declaractively in the TemplateColumn.


AddThis Social Bookmark Button