[ASP.NET]GridView在編輯模式下的欄位寬度控制

摘要:[ASP.NET]GridView在編輯模式下的欄位寬度控制


問題:

GridView在進入編輯模式時,Textbox的欄位都會變的很大

導致GridView超出頁面,讓畫面不是很好看

經過一番搜尋,果然大家都有碰到這樣的問題


    '控制GV在編輯時的欄位大小
    Protected Sub GridView3_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView3.RowDataBound
        If e.Row.RowState = (DataControlRowState.Edit Or DataControlRowState.Alternate) OrElse e.Row.RowState = DataControlRowState.Edit Then
            Dim colText As TextBox
            For i As Integer = 0 To e.Row.Cells.Count - 1
                If e.Row.Cells(i).Controls.Count <> 0 Then
                    colText = TryCast(e.Row.Cells(i).Controls(0), TextBox)
                    If colText IsNot Nothing Then
                        colText.Width = Unit.Pixel(60)  '寬度設定
                    End If
                End If
            Next
        End If

    End Sub


在此作為記錄
參考:http://topic.csdn.net/u/20071112/14/810dffb1-443b-4d66-9d2c-015d549637e9.html