Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Re: asp:datagrid control


Message #1 by "Colin Wisdom" <colin_wisdom@h...> on Fri, 6 Jul 2001 13:05:01
Mats,



I have managed to use bound columns in beta 2, however I'm binding them at 

run time.



I have a dataset, with one table and I loop trough the columns in the data 

set and create the bound columns I require. Below is an extract of the 

code.



Hope it helps,



Colin



Dim bcCol as BoundColumn



For i = 0 To dsData.Tables(0).Columns.Count - 1

   With dsData.Tables(0).Columns(i)

      Select Case .ColumnName

         Case "RecordID"

            bcCol = New BoundColumn()

            bcCol.DataField = .ColumnName

            bcCol.HeaderText = "ID"

            dgDataGrid.Columns.Add(bcCol)

         Case "EntryDate"

            bcCol = New BoundColumn()

            bcCol.DataField = .ColumnName

            bcCol.HeaderText = "Date"

            bcCol.ItemStyle.HorizontalAlign = HorizontalAlign.Left

            bcCol.DataFormatString = "{0:d}"

            dgDataGrid.Columns.Add(bcCol)

      End Select

   End With

Next



dgDataGrid.DataBind()



> Why can't you use boundcolumns with in asp.net beta2?

> Error msg:

> Literal content ('<asp:BoundColumn HeaderText"Id" 

DataField=3D"userid"/>') 

> is

> not allowed within a 'System.Web.UI.WebControls.DataGridColumnCollection'

> 

> /Mats Boberg

  Return to Index