Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Adding columns dynamically

Thread Tools

Adding columns dynamically

Peter Kamitz
Posts: n/a

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.DataSource = MyDataView


end BindData

Reply With Quote
Imtiaz Hussain
Posts: n/a
Is C1BoundColumn a custom template column?
Here is a sample that adds a template columns to the datagrid dynamically.

If this doesnt relate to your issue, please post the complete error message.

Hope this Helps.
Imtiaz Hussain.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding columns dynamically to data grid Roger Frei ASP .Net 2 06-15-2007 11:48 AM
Dynamically adding columns to a WebForm datagrid herman404 ASP .Net 1 06-20-2006 10:33 PM
When dynamically adding columns to a GridView control, where do you place the code? keithb ASP .Net 0 05-04-2006 02:21 PM
Adding Columns to Datagrid Dynamically Sal ASP .Net Datagrid Control 1 02-28-2004 09:32 PM
Dynamically Adding Bound Columns Won't Sort Mark ASP .Net Datagrid Control 2 11-26-2003 12:15 PM