1

How can I have a datagridview that will autogenerate a textbox instead of a label?

Dested
  • 6,294
  • 12
  • 51
  • 73

1 Answers1

3

In short, you can't. You could inherit from a gridview and implement it yourself. It could look something like this:

Public Class MyGrid
Inherits GridView


Private Sub MyGrid_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Me.RowDataBound
  If Me.AutoGenerateColumns = True Then
    If e.Row.RowType = DataControlRowType.DataRow Then
        For Each c As TableCell In e.Row.Cells
            Dim tb As New TextBox()
            tb.Text = c.Text
            c.Controls.Clear()
            c.Controls.Add(tb)
        Next
    End If
    End If
End Sub
brendan
  • 29,308
  • 20
  • 68
  • 109
  • For the record it doesnt need to overload the class, if its just for a single problem you can just handle dgv.RowDataBound. Thousand thanks. – Dested Feb 06 '09 at 21:35