Cassio Posted November 27, 2003 Posted November 27, 2003 Im adding datagrids dinamically into a page, so I have to do everything in the codebehind. The problem is that I cant add the event handler for the EditCommand button Heres some code Dim colEdit As New WebControls.EditCommandColumn() colEdit.CancelText = "Cancelar" colEdit.UpdateText = "OK" colEdit.EditText = "Editar" colEdit.ButtonType = ButtonColumnType.LinkButton dg.Columns.Add(colEdit) AddHandler dg.EditCommand, New DataGridCommandEventHandler(AddressOf dg_EditCommand) I can make the ItemDataBound event bubble, but the EditCommand isnt working. Any help would be appreciated! Thanks Quote Stream of Consciousness (My blog)
Cassio Posted November 27, 2003 Author Posted November 27, 2003 I forgot to mention the Edit method im using to try to catch the event: Public Sub dg_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) CType(source, DataGrid).EditItemIndex = e.Item.ItemIndex End Sub Quote Stream of Consciousness (My blog)
Moderators Robby Posted November 27, 2003 Moderators Posted November 27, 2003 Is it firing? If it is then do this dg.EditItemIndex = e.Item.ItemIndex OR DirectCast(source, DataGrid).EditItemIndex = e.Item.ItemIndex Quote Visit...Bassic Software
Cassio Posted November 27, 2003 Author Posted November 27, 2003 (edited) Robby, it isnt firing. I dont know why. I found this line of code in a site: Grid.EditCommand += new DataGridCommandEventHandler(GridEdit); Its c#, how can I do that in VB? Edited November 27, 2003 by Cassio Quote Stream of Consciousness (My blog)
*Experts* Bucky Posted November 27, 2003 *Experts* Posted November 27, 2003 What you're doing in VB is the same as that C# code. The only difference is the placement of the code. You need to place your code in the InitializeComponent method of the codebehind page, not in Page_Load (as I'm assuming that's where it is ATM). Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Cassio Posted November 27, 2003 Author Posted November 27, 2003 I´m using it inside a procedure that generates more than one datagrid and adds it to the page. I cant add it in the InitializeComponent because I dont know how many grids im gonna need. Quote Stream of Consciousness (My blog)
fadi Posted November 28, 2003 Posted November 28, 2003 i dont know if the syntax of the addhandler is correct i usually write AddHandler dg.EditCommand, AddressOf dg_EditCommand instead of AddHandler dg.EditCommand, New DataGridCommandEventHandler(AddressOf dg_EditCommand) i hope this helps Quote
Moderators Robby Posted November 28, 2003 Moderators Posted November 28, 2003 Fadi, that's exactly what Cassio has in his first post. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.