Button Column



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
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) = 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
End With
'return a DataView to the DataTable
CreateProjectDataSource = New DataView(dt)
Catch ex As Exception
End Try
End Function




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?


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

Similar Threads