473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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?

[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;Conne ct 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.CloseConne ction)
grdArtiklar.DataSource = s
grdArtiklar.DataBind()
s.Close()
objConnectionMain.Close()
End Function

End Class
[/VB]

Jul 21 '05 #1
1 1216
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...
"PrinsOlsson" wrote:
[VB]
Protected WithEvents grdArtiklar As System.Web.UI.WebControls.DataGrid
[/VB]

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Daniel Walzenbach | last post by:
Hi, I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
4
by: nmosafi | last post by:
I have a datagrid that I am binding to a custom collection, and I am having problems with data binding in an ASP.NET datagrid (1.1 framework). As a simple example, imagine a class called...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
6
by: Agnes | last post by:
I understand it is impossible, but still curious to know "Can I freeze several column in the datagrid, the user can only scroll the first 3 columns (not verical), for the rest of the coulumn, it is...
0
by: Melson | last post by:
Hi Can anyone help me with this problem. I've a form1(entry form) with datagrid which bound to a dataset (datagrid.setdatabinding(dataset,"table")). I've a public class Capturekey in form1 which...
1
by: PrinsOlsson | last post by:
I have 2 classes. I want to update an datagrid (grdArtiklar) from another class. How to use the datagrid from the other class? Imports System.IO Imports ByteFX.Data Imports...
5
nmm32
by: nmm32 | last post by:
I have a DataGrid which displays data with the aid of a procedure. I have tested the procedure inside the database and it is working fine. I have another procedure which adds another row to the...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.