Home All Groups Group Topic Archive Search About
Author
6 Apr 2005 8:49 AM
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

Author
6 Apr 2005 9:20 AM
otabekhm
I am not sure but probably you have to use ColumnName property instead

Otabek
Author
6 Apr 2005 10:35 AM
Cor Ligthert
Author
6 Apr 2005 1:24 PM
Nikolay Petrov
What about ASP datagrid?



Show quoteHide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message
news:%23KwYoRpOFHA.3336@TK2MSFTNGP09.phx.gbl...
> Nikolay,
>
> In my opinion is in this page exactly described what you want.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridcolumnstyleclassheadertexttopic.asp
>
> I hope this helps,
>
> Cor
>
Author
6 Apr 2005 3:52 PM
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
Author
8 Apr 2005 7:01 AM
Nikolay Petrov
Thanks a lot Cor.
Awesome.