How to use datagrid from another class

G

Guest

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

[VB]


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.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

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

'pao
' 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
'pao

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'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.
InitializeComponent()
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
grdArtiklar.ItemCommand
'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
Response.Write("<br>Ni ville se info om ArtNr: " & kolumn0 & ".")
Dim artikel As New Artikel
artikel.VisaArtikelRad(kolumn0)

End If

grdArtiklar.DataBind()

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;server=bla.test.com;Connect Timeout=30;user
id=testuser; pwd=psw")

objConnectionMain.Open()

Dim mysqlComm As New MySqlCommand("SELECT * FROM 2004artiklar WHERE
ArtNr='" + artNr + "'", objConnectionMain)
Dim s As MySqlDataReader =
mysqlComm.ExecuteReader(CommandBehavior.CloseConnection)
grdArtiklar.DataSource = s
grdArtiklar.DataBind()
s.Close()
objConnectionMain.Close()
End Function

End Class
[/VB]
 
G

Guest

I've tried making the grid PUBLIC but then I get an error;

c:\inetpub\wwwroot\ws2005\Artikel.vb(59): Reference to a non-shared member
requires an object reference.

And I don't understand the error...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top