开发者

'Fill' is not a member of 'System.Web.UI.WebControls.DataGrid' Error

I am developing a VB.NET program to search for text in a specified column from a Datagrid. I am almost finished implementing this following the MS tutorial at: http://support.microsoft.com/kb/815680

But now I have just one compilation error:

BC30456: 'Fill' is not a member of 'System.Web.UI.WebControls.DataGrid'.

on the line that says:

dgTable.Fill(ds)

The code related to this project is as follows. Does anybody know how I can fix this please?

My global.vb file:

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

And my ASPX file:

        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

...

Now I have modified above code as follows:

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()

But now I get a different error:

BC30311: Value of type 'System.Data.DataTableCollection' cannot be converted to 'System.Data.DataTable'

Also, I'm not sure if it is good to be declaring these variables new like this since I believe I already call them new elsewhere in my code.


Instead of:

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

try:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜