2011-05-16 35 views
0

我正在開發一個VB.NET程序,以便從Datagrid的指定列中搜索文本。我幾乎完成了實施這一下面的MS教程: http://support.microsoft.com/kb/815680'Fill'不是'System.Web.UI.WebControls.DataGrid'的成員錯誤

但現在我只有一個編譯錯誤:

BC30456: 'Fill' is not a member of '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: Value of type 'System.Data.DataTableCollection' cannot be converted to 'System.Data.DataTable'

另外,我不確定是否應該將這些變量聲明爲新的,因爲我相信我已經在代碼中將它們稱爲新的。

回答

1

相反的:

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

嘗試:

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

我同意,但不幸的是我的框架或VS的版本不支持的DataGridView。不過,我知道可以用DataGrid來實現。請提供任何提示? – salvationishere 2011-05-16 19:54:07

+0

再次看看我的答案,我剛剛從您正在使用的教程中抓取了一個示例。 – Jack 2011-05-16 20:19:39

+0

謝謝,傑克,但你能看到我的編輯?我嘗試了您的解決方案,但它現在給我一個不同的錯誤。 – salvationishere 2011-05-16 20:37:53

相關問題