VB.NET dynamically create datagrid and set its datasource

D

dyw55a

Donna Mar 15, 10:11 am show options

Newsgroups: microsoft.public.dotnet.framework.adonet
From: "Donna" <[email protected]> - Find messages by this author
Date: 15 Mar 2005 10:11:56 -0800
Local: Tues, Mar 15 2005 10:11 am
Subject: VB.NET dynamically create datagrid and set its datasource
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse

I try to dynamically add datagrid to my web form in VB.NET. But when I

try to setup the datasource, the DATASOURCE is not the property of
datagrid. Anybody know the reason?


I tried the same thing in C#, the DATASOURCE is the property of
datagrid and it works great.


thanks for your help
 
S

Scott Allen

Hi Donna:

DataSource is a property available on a DataGrid for all the
languages. Are you saying DataSource doesn't appear in the properties
window? Or doesn't compile?
 
D

dyw55a

Actually datasource is not the property of datagrid when you create the
datagrid in the run time instead of design time. Here is the code
Public Sub CreateGrid()
'declare a new datagrid and set properties
Dim DataGrid1 As New DataGrid()

'bind datagrid
'*************************************
'I will get error in here and tell me that
'datasource is not the property of DataGrid1
DataGrid1.DataSource = GetDataSet()
DataGrid1.DataBind()

'add datagrid to the page
Page.Controls(1).Controls.Add(DataGrid1)

End Sub

Any thought?
thanks
 
S

Scott Allen

Hi:


Actually datasource is not the property of datagrid when you create the
datagrid in the run time instead of design time. Here is the code
Public Sub CreateGrid()
'declare a new datagrid and set properties
Dim DataGrid1 As New DataGrid()

'bind datagrid
'*************************************
'I will get error in here and tell me that
'datasource is not the property of DataGrid1
DataGrid1.DataSource = GetDataSet()
DataGrid1.DataBind()

'add datagrid to the page
Page.Controls(1).Controls.Add(DataGrid1)

End Sub

Any thought?
thanks

That seems odd, the only thing I can think of is that you have another
class by the name of DataGrid. Try:

Dim DataGrid1 As New System.Web.UI.WebControls.DataGrid

Any luck?
 
D

dyw55a

Scott,
Thank you very much. I thought that I import the
System.Web.UI.WebControls, then I could use datagrid directly. You
are right that there should be another class called datagrid somewhere
which I even did not know it exists. Thanks again

Donna
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top