C
Chris
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
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