Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2005, 07:55 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default Keeping DataGrid Column sizes static

Is there a way to specify the width of the text-boxes that a datagrid renders when in edit mode, other than by using a template column, so that the overal width of the datagrid remains roughly constant? The thing is scrolling off the edge of my screen when a user presses an edit button.

Thanks.

Aaron

 
Old July 30th, 2005, 03:04 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

In a handler for the ItemDataBount datagrid event, look into each cell in e.Item.Cells for a textbox control. Then explicitly define the style for it. You might be able to get away with width=100% and have the textbox fill the cell width. Seeing as the text in other rows will probably govern the overall column width, this mostly works. Here's some code:

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
    Dim txtTextBox As TextBox
    Select Case e.Item.ItemType
        Case ListItemType.EditItem
            For Each objCell As TableCell In e.Item.Cells
                If objCell.Controls.Count > 0 Then
                    If TypeOf objCell.Controls(0) Is TextBox Then
                        txtTextBox = CType(objCell.Controls(0), TextBox)
                        If txtTextBox.Text.Length > 150 Then
                            txtTextBox.TextMode = TextBoxMode.MultiLine
                            txtTextBox.Rows = 4
                        End If
                        txtTextBox.Style.Item("width") = "100%"
                    End If
                End If
            Next
    End Select
End Sub


-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Datagrid Column Value vietskynet Beginning VB 6 0 August 1st, 2008 03:42 AM
non-static reports to static html files miamikk ASP.NET 2.0 Basics 0 June 4th, 2007 01:48 PM
Datagrid column values krishnasamaga C# 2005 1 August 8th, 2006 06:54 AM
Datagrid template column sonurijs ASP.NET 1.x and 2.0 Application Design 1 September 27th, 2005 12:55 PM
DataGrid column width johanyu VS.NET 2002/2003 0 October 30th, 2004 05:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.