DataGridView Autogeneratecolumns as TextBox而不是label

时间:2009-02-06 20:42:21

标签: c# asp.net vb.net datagridview autogeneratecolumn

我如何拥有一个自动生成文本框而不是标签的datagridview?

1 个答案:

答案 0 :(得分:3)

总之,你不能。您可以从gridview继承并自己实现它。它可能看起来像这样:

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