WyldGynjer
MIS
I am creating a datagrid dynamically,I have 3 columns -
1 - data bound column from a dataset that is generated based on my parenty key
2 - Input text box
3 - button that will be used to save the data entered in the text box
Problem:
My button does nothing. It's like it doesn't fire any event.
Code:
I am trying to create a child datagrid ( a datagrid that is displayed in the row beneath a "parent" row that dispalys many rows from another table) - so I call this function within the parent datagrids ItemDataBound function.
' code to create my child dataset: oBillDS
' code to create the datagrid
NewDg = New DataGrid
NewDg.AutoGenerateColumns = False
Dim cDgCol As DataColumn
For Each cDgCol In oBillDS.Tables(0).Columns
If cDgCol.ColumnName = "Pnum" Then
NewDg.Columns.Add(CreateBoundControl(cDgCol))
End If
Next
NewDg.Width = Unit.Percentage(100)
Dim tc1 As New TemplateColumn
tc1.HeaderTemplate = New DataGridTemplate(ListItemType.Header, "Amount Paid")
tc1.ItemTemplate = New DataGridTemplate(ListItemType.Item, "From DB Amt Paid")
tc1.EditItemTemplate = New DataGridTemplate(ListItemType.EditItem, "AmtPaid")
tc1.FooterTemplate = New DataGridTemplate(ListItemType.Footer, "NoFooter")
NewDg.Columns.Add(tc1)
Dim txtBoxColumn As New ButtonColumn
txtBoxColumn.CommandName = "MyCommmand"
txtBoxColumn.Text = "Update"
txtBoxColumn.ButtonType = ButtonColumnType.PushButton
' my attempt to add a handler for my datagrid
AddHandler NewDg.ItemCommand, AddressOf NewDG_EditCommand
NewDg.Columns.Add(txtBoxColumn)
NewDg.EnableViewState = True
NewDg.EditItemIndex = 0
NewDg.DataSource = oBillDS
NewDg.DataBind()
Dim sw As New System.IO.StringWriter
Dim htw As New System.Web.UI.HtmlTextWriter(sw)
NewDg.RenderControl(htw)
Dim DivStart As String = "<DIV id=uniquename" + e.Item.ItemIndex.ToString("' style='DISPLAY: none>'")
Dim DivBody As String = sw.ToString()
Dim DivEnd As String = "</DIV>"
Dim FullDIV As String = DivStart + DivBody + DivEnd
Dim LastCellPosition As Integer = e.Item.Cells.Count - 1
Dim NewCellPosition As Integer = e.Item.Cells.Count - 2
e.Item.Cells(0).ID = "CellInfo" + e.Item.ItemIndex.ToString()
If e.Item.ItemType = ListItemType.Item Then
e.Item.Cells(LastCellPosition).Controls.Add(New LiteralControl("</td><tr><td bgcolor='f5f5f5'></td><td colspan='" + NewCellPosition.ToString + "'>" + FullDIV))
Else
e.Item.Cells(LastCellPosition).Controls.Add(New LiteralControl("</td><tr><td bgcolor='d3d3d3'></td><td colspan='" + NewCellPosition.ToString + "'>" + FullDIV))
End If
e.Item.Cells(0).Attributes("onmouseover") = "this.style.cursor='pointer'"
e.Item.Cells(0).Attributes("onmouseout") = "this.style.cursor='pointer'"
' Sub that I thought would fire - but doesn't
Public Sub NewDG_EditCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Response.Redirect(" End Sub
Does anyone have any suggestions as to why my event is never fired. I thought the buttonColumn would fire the ItemCommand event of the datagrid --- if anyone has any thoughts - I'd greatly appreciate them.
1 - data bound column from a dataset that is generated based on my parenty key
2 - Input text box
3 - button that will be used to save the data entered in the text box
Problem:
My button does nothing. It's like it doesn't fire any event.
Code:
I am trying to create a child datagrid ( a datagrid that is displayed in the row beneath a "parent" row that dispalys many rows from another table) - so I call this function within the parent datagrids ItemDataBound function.
' code to create my child dataset: oBillDS
' code to create the datagrid
NewDg = New DataGrid
NewDg.AutoGenerateColumns = False
Dim cDgCol As DataColumn
For Each cDgCol In oBillDS.Tables(0).Columns
If cDgCol.ColumnName = "Pnum" Then
NewDg.Columns.Add(CreateBoundControl(cDgCol))
End If
Next
NewDg.Width = Unit.Percentage(100)
Dim tc1 As New TemplateColumn
tc1.HeaderTemplate = New DataGridTemplate(ListItemType.Header, "Amount Paid")
tc1.ItemTemplate = New DataGridTemplate(ListItemType.Item, "From DB Amt Paid")
tc1.EditItemTemplate = New DataGridTemplate(ListItemType.EditItem, "AmtPaid")
tc1.FooterTemplate = New DataGridTemplate(ListItemType.Footer, "NoFooter")
NewDg.Columns.Add(tc1)
Dim txtBoxColumn As New ButtonColumn
txtBoxColumn.CommandName = "MyCommmand"
txtBoxColumn.Text = "Update"
txtBoxColumn.ButtonType = ButtonColumnType.PushButton
' my attempt to add a handler for my datagrid
AddHandler NewDg.ItemCommand, AddressOf NewDG_EditCommand
NewDg.Columns.Add(txtBoxColumn)
NewDg.EnableViewState = True
NewDg.EditItemIndex = 0
NewDg.DataSource = oBillDS
NewDg.DataBind()
Dim sw As New System.IO.StringWriter
Dim htw As New System.Web.UI.HtmlTextWriter(sw)
NewDg.RenderControl(htw)
Dim DivStart As String = "<DIV id=uniquename" + e.Item.ItemIndex.ToString("' style='DISPLAY: none>'")
Dim DivBody As String = sw.ToString()
Dim DivEnd As String = "</DIV>"
Dim FullDIV As String = DivStart + DivBody + DivEnd
Dim LastCellPosition As Integer = e.Item.Cells.Count - 1
Dim NewCellPosition As Integer = e.Item.Cells.Count - 2
e.Item.Cells(0).ID = "CellInfo" + e.Item.ItemIndex.ToString()
If e.Item.ItemType = ListItemType.Item Then
e.Item.Cells(LastCellPosition).Controls.Add(New LiteralControl("</td><tr><td bgcolor='f5f5f5'></td><td colspan='" + NewCellPosition.ToString + "'>" + FullDIV))
Else
e.Item.Cells(LastCellPosition).Controls.Add(New LiteralControl("</td><tr><td bgcolor='d3d3d3'></td><td colspan='" + NewCellPosition.ToString + "'>" + FullDIV))
End If
e.Item.Cells(0).Attributes("onmouseover") = "this.style.cursor='pointer'"
e.Item.Cells(0).Attributes("onmouseout") = "this.style.cursor='pointer'"
' Sub that I thought would fire - but doesn't
Public Sub NewDG_EditCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Response.Redirect(" End Sub
Does anyone have any suggestions as to why my event is never fired. I thought the buttonColumn would fire the ItemCommand event of the datagrid --- if anyone has any thoughts - I'd greatly appreciate them.