'Fill'不是'System.Web.UI.WebControls.DataGrid'错误的成员

时间:2011-05-16 19:13:54

标签: vb.net datagrid

我正在开发一个VB.NET程序,用于从Datagrid中搜索指定列中的文本。我几乎完成了以下MS教程的实现: http://support.microsoft.com/kb/815680

但现在我只有一个编译错误:

  

BC30456:'填充'不属于   'System.Web.UI.WebControls.DataGrid'。

在线上说:

dgTable.Fill(ds)

与该项目相关的代码如下。有人知道我该如何解决这个问题吗?

我的global.vb文件:

Namespace GlobalFunctions
    Public Class GlobalF
        Public Shared Function GlobalF_Load(ByVal dgTable As DataGrid)
            dgTable.Fill(ds)
            dv = New DataView(ds.Tables)
            dgTable.DataSource = dv
            dv.Sort = "Part No."
            CM = (System.Windows.Forms.CurrencyManager)
            dgTable.BindingContext([dv])
            Dim sender As New sender()

            dv.ListChanged += New ListChangedEventHandler(dv_ListChangedEvent)
        End Function

        Public Shared Function btnFind_Click(ByVal sender As Object, ByVal e As EventArgs)
            If (txtFind.Text = "") Then
                Response.write("Enter some criteria to find.")
                txtFind.Focus()
            Else
                Dim i As Int
                i = dv.Find(txtFind.Text)
                If (i > dv.Table.Rows.Count Or i < 0) Then
                    Response.Write("Record Not found")
                Else
                    CM.Position = i
                End If
            End If
        End Function

        Private Shared Function dv_ListChangedEvent(ByVal sender As Object, ByVal e As ListChangedEventArgs) Handles btnFind.ListChanged
            If (dv.Sort.Substring((dv.Sort.Length - 4), 4) = "DESC") Then
                lblFind.Text = "Enter Search Criteria " + dv.Sort.Substring(0, dv.Sort.Length - 5)
            Else
                lblFind.Text = "Enter Search Criteria " + dv.Sort
            End If
        End Function

我的ASPX文件:

        Public DSTableData As New System.Data.DataSet
        Public dv As New DataView

        Sub Main()
            '------------------------- Query database and get arrays for the chart and bind query results to datagrid ----------------------------------------                                                              

            If check1.Checked Then
                DSTableData = GlobalFunctions.GlobalF.FillSparePartsTable(1)
            Else
                DSTableData = GlobalFunctions.GlobalF.FillSparePartsTable(0)
            End If

            'dv = DataView(DSTableData(0))
            dgTable.DataSource = DSTableData
            dgTable.DataBind()

            GlobalFunctions.GlobalF.GlobalF_Load(dgTable)

        End Sub

        Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
            If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
                Dim thepriority As Integer

...

现在我修改了上面的代码如下:

Public Shared Function GlobalF_Load(ByVal dgTable As DataGrid)
            Dim dv As New DataView
            Dim ds As New DataSet
            dv = New DataView(ds.Tables())
            dgTable.DataSource = dv
            dv.Sort = "Part No."
            CM = (System.Windows.Forms.CurrencyManager)
            dgTable.BindingContext([dv])
            Dim sender As New sender()

但现在我得到了一个不同的错误:

  

BC30311:类型的值   'System.Data.DataTableCollection'   无法转换为   'System.Data.DataTable'

此外,我不确定是否可以将这些变量声明为新的,因为我相信我已经在我的代码中将其称为新的。

1 个答案:

答案 0 :(得分:1)

而不是:

dgTable.Fill(ds)
dv = New DataView(ds.Tables)
dgTable.DataSource = dv

尝试:

dv= New DataView(ds.Tables("table name")
dgTable.DataSource = dv