Button Column

Discussion in 'ASP .Net' 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, it would help seeing an example of what you're trying to do
    (describing the business problem, not the code), but for one why are you
    trying to add the button to the datatable and not the datagrid? Why can't you
    use <columns>? Are you forced to autogenerate the columns for some reason? Is
    the button exactly the same for each column, or is it on/off depending on the
    data that's in that row?

    Bill

    "Chris" wrote:

    > 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
    >
    >
    >
     
    =?Utf-8?B?QmlsbCBCb3Jn?=, Apr 22, 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:
    586
    Guest
    Nov 10, 2003
  2. Jim Hammond
    Replies:
    1
    Views:
    3,623
    bruce barker
    Nov 26, 2003
  3. Hai Nguyen
    Replies:
    0
    Views:
    404
    Hai Nguyen
    Jan 16, 2004
  4. carlos perez
    Replies:
    0
    Views:
    417
    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:
    604
    =?Utf-8?B?V2FyYW4=?=
    Aug 9, 2005
Loading...

Share This Page