D
Donna
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? Here is my code:
Public Sub CreateGrid()
'declare a new datagrid and set properties
Dim DataGrid1 As New DataGrid()
DataGrid1.ShowHeader = True
DataGrid1.AutoGenerateColumns = False
DataGrid1.SelectedItemStyle.BackColor = Color.Yellow
'add bound columns to the datagrid
Dim datagridcol As New BoundColumn()
datagridcol.HeaderText = "Last Name"
datagridcol.DataField = "lastname"
DataGrid1.Columns.Add(datagridcol)
datagridcol = New BoundColumn()
datagridcol.HeaderText = "First Name"
datagridcol.DataField = "firstname"
DataGrid1.Columns.Add(datagridcol)
'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
I tried the same thing in C#, the DATASOURCE is the property of
datagrid and it works great.
thanks for any help
try to setup the datasource, the DATASOURCE is not the property of
datagrid. Anybody know the reason? Here is my code:
Public Sub CreateGrid()
'declare a new datagrid and set properties
Dim DataGrid1 As New DataGrid()
DataGrid1.ShowHeader = True
DataGrid1.AutoGenerateColumns = False
DataGrid1.SelectedItemStyle.BackColor = Color.Yellow
'add bound columns to the datagrid
Dim datagridcol As New BoundColumn()
datagridcol.HeaderText = "Last Name"
datagridcol.DataField = "lastname"
DataGrid1.Columns.Add(datagridcol)
datagridcol = New BoundColumn()
datagridcol.HeaderText = "First Name"
datagridcol.DataField = "firstname"
DataGrid1.Columns.Add(datagridcol)
'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
I tried the same thing in C#, the DATASOURCE is the property of
datagrid and it works great.
thanks for any help