DataGrid editing: how to size textboxes?

  • Thread starter Thread starter Pavel Gusak
  • Start date Start date
P

Pavel Gusak

Hello.
I've found DataGrid built-in edit functionality useless. My DataGrid has 9
columns, and is shown just nice until I press 'Edit' on a row. ASP.NET
creates 9 TextBoxes, all the same very big size, so my table becomes
3-screen-wide or so. How can I set size for the TextBoxes?
Thanks.
 
Hi Pavel,

You can adjust the text boxes in the grid's ItemDataBound event. Here's an
example where I change the width of the text box to 25 pixels. Note - you
may have to experiment to find the control positions of your text boxes. In
my sample it's in position 1 (zero based, a literal control is in position
zero).


Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
CType(e.Item.Cells(1).Controls(1), WebControls.TextBox).Width =
Unit.Pixel(25)
End If
End Sub


Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
 
Back
Top