How to use Datagrid from another class

I have 2 classes. I want to update an datagrid (grdArtiklar) from another
class. How to use the datagrid from the other class?

I have tried;
Public WithEvents grdArtiklar As System.Web.UI.WebControls.DataGrid

but then I get the error message;
c:inetpubwwwrootws2005Artikel.vb(59): Reference to a non-shared member requires an object reference.

Any experts out there, or not as newbie as I am ? :-)

Imports System.IO
Imports ByteFX.Data
Imports ByteFX.Data.MySqlClient
Imports ws2005.Artikel

Public Class main
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
Private Sub

End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

' Declare a Connection object that is global in scope
Dim objConnectionMain As MySqlConnection
Dim objDataAdapter As MySqlDataAdapter
Dim objDataSet As DataSet
Dim objDataView As DataView
Dim val As String
Protected WithEvents grdArtiklar As System.Web.UI.WebControls.DataGrid
Protected WithEvents grdMeny As System.Web.UI.WebControls.DataGrid
Protected WithEvents grdTillverkare As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here


End Sub

Private Sub grdArtiklar_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
'e.Item is the row of the table where the button was clicked.

Dim kolumn0 As String = e.Item.Cells(0).Text
Dim kolumn1 As String = e.Item.Cells(1).Text
Dim kolumn2 As String = "" ' e.Item.Cells(2).Text

If (e.CommandName = "VisaArtikelInfo") Then
Ni ville se info om ArtNr: " & kolumn0 & ".")
Dim artikel As New Artikel

End If


End Sub

End Class

Public Class Artikel

Function VisaArtikelRad(ByVal artNr As String)
Return runSQL(artNr)
End Function

Function runSQL(ByVal artNr As String)

Dim objConnectionMain = New MySqlConnection("Persist Security
Info=False;database=test;;Connect Timeout=30;user
id=testuser; pwd=psw")


Dim mysqlComm As New MySqlCommand("SELECT * FROM 2004artiklar WHERE
ArtNr='" + artNr + "'", objConnectionMain)
Dim s As MySqlDataReader =

'''' Here is where it gets wrong. grdArtiklar doesn't "exist".
grdArtiklar.DataSource = s

End Function

End Class


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!