DataGrid editing: how to size textboxes?

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.
 
M

Mike Moore [MSFT]

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.


--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top