Adding columns dynamically

P

Peter Kamitz

hi,

I always get the error: Item has already been added. Key in dictionary: "0"
Key being added: "0" ----when trying to databind the webgrid with
dynamically added columns.

All the columns are added without any problems, but when it comes to the
databinding (=> MyGrid.DataBind()) the error above is thrown!



here is my source code. has anybody an idea why this is not working?


private sub BindData()

Dim MyDataView As New DataView

Dim MyCol As New DataColumn

Dim MyC1Col As New C1BoundColumn



MyDataView = MyReport.GetSales()

MyGrid.AutoGenerateColumns = False

For Each MyCol In MyDataView.Table.Columns

MyC1Col.HeaderText = MyCol.ColumnName

MyC1Col.DataField = MyCol.ColumnName

MyGrid.Columns.Add(MyC1Col)

Next

MyGrid.DataSource = MyDataView

MyGrid.DataBind()



end BindData
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top