Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to use Datagrid from another class

CaspherCaspher Posts: 1Member
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 ? :-)


[code]
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
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("
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)


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

s.Close()
objConnectionMain.Close()
End Function

End Class


[/code]

Sign In or Register to comment.