button column

Discussion in 'ASP .Net Datagrid Control' started by Chris, Apr 22, 2005.

  1. Chris

    Chris Guest

    I need to add a button column to my datagrid. I need to be able to do this
    at runtime. I can not have the tag <columns></columns> in my aspx page.

    This is where I am at

    Private Function CreateProjectDataSource(ByVal projectds As DataSet, ByVal
    dg As DataGrid) As ICollection
    Try
    Dim btn As System.Web.UI.WebControls.Button
    Dim dt As DataTable
    Dim dr As DataRow
    dt = New DataTable
    Dim i As Integer
    dg.AllowSorting = True
    btn = New System.Web.UI.WebControls.Button
    btn.ID = "btn" & i
    btn.Visible = True
    btn.Text = "Edit"
    btn.CommandName = "btn" & i

    <!-- i am stuck with this
    dt.columns.add(new buttomcolumn())<!--- cant do that.. how do i do this



    dt.Columns.Add(New DataColumn("Project Name", GetType(String)))
    dt.Columns.Add(New DataColumn("Project Category", GetType(String)))
    dt.Columns.Add(New DataColumn("Customer", GetType(String)))
    dt.Columns.Add(New DataColumn("Budget Hours", GetType(Double)))
    'Make some rows and put some sample data in
    For i = 0 To projectds.Tables(0).Rows.Count - 1
    With projectds.Tables(0).Rows(i)
    dr = dt.NewRow()
    'dr(0).cells.add(btn)
    dr(0) = btn
    dr(1) = .Item("Project Name")
    dr(2) = .Item("Project Category")
    dr(3) = .Item("Customer")
    dr(4) = .Item("Budget Hours")
    'add the row to the datatable
    dt.Rows.Add(dr)
    End With
    Next
    'return a DataView to the DataTable
    CreateProjectDataSource = New DataView(dt)
    Catch ex As Exception
    End Try
    End Function

    THanks

    Chris
    Chris, Apr 22, 2005
    #1
    1. Advertising

  2. Chris

    Brock Allen Guest

    It's ButtonColumn, not ButtomColumn. Other than the typo, it should be possible
    to add a new column dynamically.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > I need to add a button column to my datagrid. I need to be able to do
    > this at runtime. I can not have the tag <columns></columns> in my aspx
    > page.
    >
    > This is where I am at
    >
    > Private Function CreateProjectDataSource(ByVal projectds As DataSet,
    > ByVal
    > dg As DataGrid) As ICollection
    > Try
    > Dim btn As System.Web.UI.WebControls.Button
    > Dim dt As DataTable
    > Dim dr As DataRow
    > dt = New DataTable
    > Dim i As Integer
    > dg.AllowSorting = True
    > btn = New System.Web.UI.WebControls.Button
    > btn.ID = "btn" & i
    > btn.Visible = True
    > btn.Text = "Edit"
    > btn.CommandName = "btn" & i
    > <!-- i am stuck with this
    > dt.columns.add(new buttomcolumn())<!--- cant do that.. how do i do
    > this
    > dt.Columns.Add(New DataColumn("Project Name", GetType(String)))
    > dt.Columns.Add(New DataColumn("Project Category", GetType(String)))
    > dt.Columns.Add(New DataColumn("Customer", GetType(String)))
    > dt.Columns.Add(New DataColumn("Budget Hours", GetType(Double)))
    > 'Make some rows and put some sample data in
    > For i = 0 To projectds.Tables(0).Rows.Count - 1
    > With projectds.Tables(0).Rows(i)
    > dr = dt.NewRow()
    > 'dr(0).cells.add(btn)
    > dr(0) = btn
    > dr(1) = .Item("Project Name")
    > dr(2) = .Item("Project Category")
    > dr(3) = .Item("Customer")
    > dr(4) = .Item("Budget Hours")
    > 'add the row to the datatable
    > dt.Rows.Add(dr)
    > End With
    > Next
    > 'return a DataView to the DataTable
    > CreateProjectDataSource = New DataView(dt)
    > Catch ex As Exception
    > End Try
    > End Function
    > THanks
    >
    > Chris
    >
    Brock Allen, Apr 25, 2005
    #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. Guest
    Replies:
    2
    Views:
    584
    Guest
    Nov 10, 2003
  2. Jim Hammond
    Replies:
    1
    Views:
    3,615
    bruce barker
    Nov 26, 2003
  3. Hai Nguyen
    Replies:
    0
    Views:
    402
    Hai Nguyen
    Jan 16, 2004
  4. carlos perez
    Replies:
    0
    Views:
    415
    carlos perez
    Jun 8, 2004
  5. =?Utf-8?B?V2FyYW4=?=

    HyperLink Column and Button Column in a DataGrid

    =?Utf-8?B?V2FyYW4=?=, Aug 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    600
    =?Utf-8?B?V2FyYW4=?=
    Aug 9, 2005
Loading...

Share This Page