I have a datagrid - datagrid1.
At runtime, I am adding a ButtonColumn (Link Button) like so:
Dim bc As New ButtonColumn
bc.HeaderText = Format(dr.Item("PAYMENT_DATE"), "Short Date")
bc.DataTextField = Format(dr.Item("PAYMENT_DATE"), "Short Date")
bc.Text = Format(dr.Item("PAYMENT_DATE"), "Short Date")
bc.ButtonType = ButtonColumnType.LinkButton
bc.CommandName = "Test"
Me.DataGrid1.Columns.Add(bc)
This works fine. It creates the proper linkbutton with the correct data.
Now, I am under the impression that when I click the buttons in this column, it is to raise the Datagrid1.ItemCommand event at which point I can find out what to do next by grabbing the .commandname text. This is not happening. When I click the button, the newly created column disappears and the datagrid reverts back to its original state (minus the buttoncolumn.) It's a postback with no event. The Datagrid1.ItemCommand event is not raised.
Does anyone have any experience in adding ButtonColumns to datagrids at runtime? If so, any advice on why this is not working correctly?
Any advice is greatly appreciated.
Zatch
At runtime, I am adding a ButtonColumn (Link Button) like so:
Dim bc As New ButtonColumn
bc.HeaderText = Format(dr.Item("PAYMENT_DATE"), "Short Date")
bc.DataTextField = Format(dr.Item("PAYMENT_DATE"), "Short Date")
bc.Text = Format(dr.Item("PAYMENT_DATE"), "Short Date")
bc.ButtonType = ButtonColumnType.LinkButton
bc.CommandName = "Test"
Me.DataGrid1.Columns.Add(bc)
This works fine. It creates the proper linkbutton with the correct data.
Now, I am under the impression that when I click the buttons in this column, it is to raise the Datagrid1.ItemCommand event at which point I can find out what to do next by grabbing the .commandname text. This is not happening. When I click the button, the newly created column disappears and the datagrid reverts back to its original state (minus the buttoncolumn.) It's a postback with no event. The Datagrid1.ItemCommand event is not raised.
Does anyone have any experience in adding ButtonColumns to datagrids at runtime? If so, any advice on why this is not working correctly?
Any advice is greatly appreciated.
Zatch