Adding columns dynamically

Discussion in 'ASP .Net Datagrid Control' started by Peter Kamitz, Oct 28, 2003.

  1. Peter Kamitz

    Peter Kamitz Guest

    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
     
    Peter Kamitz, Oct 28, 2003
    #1
    1. Advertising

  2. Imtiaz Hussain, Oct 29, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keithb
    Replies:
    0
    Views:
    2,237
    keithb
    May 4, 2006
  2. herman404
    Replies:
    1
    Views:
    458
    =?Utf-8?B?c2xlbWVu?=
    Jun 20, 2006
  3. Roger Frei

    Adding columns dynamically to data grid

    Roger Frei, Jun 15, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    2,185
    Roger Frei
    Jun 15, 2007
  4. Mark

    Dynamically Adding Bound Columns Won't Sort

    Mark, Nov 24, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    161
  5. Sal

    Adding Columns to Datagrid Dynamically

    Sal, Feb 26, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    137
Loading...

Share This Page