Datagrid problem

N

Nikolay Petrov

I have a DataSet with one DataTable in it.
When binded to a DataGrid, a get the column names in DataTable as headers
for the columns in the DataGrid.
When I created the DataColumns I set their Caption property, but it doesn't
want to show as Column header in the DataGrid. What I do wrong?

Code:
Dim DS1 As New DataSet
Dim dT As New DataTable("Table Name")
Dim dCol As DataColumn
dCol = New System.Data.DataColumn("Col1")
dCol.DataType = System.Type.GetType("System.String")
dCol.Caption = "Column 1"
dT.Columns.Add(dCol)
dCol = New System.Data.DataColumn("Col2")
dCol.DataType = System.Type.GetType("System.String")
dCol.Caption = "Column 2"
dT.Columns.Add(dCol)
DS1.Tables.Add(dT)
DataGrid1.DataSource = DS1.Tables(0)
DataGrid1.DataBind
 
C

Cor Ligthert

Nikolay,

After some trying I succeeded with that.

:)

\\\Needs a datagrid on a webform
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim DS1 As New DataSet
Dim dT As New DataTable("Table Name")
dT.Columns.Add("Col1", GetType(System.String))
dT.Columns.Add("Col2", GetType(System.String))
dT.LoadDataRow(New Object() {"Nikolay", "Cor"}, True)
DS1.Tables.Add(dT)
DataGrid1.DataSource = DS1.Tables(0)
Dim b1 As New BoundColumn
Dim b2 As New BoundColumn
b1.DataField = "Col1"
b2.DataField = "Col2"
b1.HeaderText = "Question"
b2.HeaderText = "Answer"
DataGrid1.Columns.Add(b1)
DataGrid1.Columns.Add(b2)
DataGrid1.AutoGenerateColumns = False
DataGrid1.DataBind()
End Sub
///

I hope this helps a little bit?

Cor
 

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