DataGrid Buttons
-
Hi, Im using a DataGrid to display some info from the DB. Instead of the standard edit column i created a template column, with a button in it. If i use a Linkbutton it all works fine. However if i use a standard button nothing happens. Ive given the button a CommandName of Edit, and under the ItemCommand ive got:
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { //performs relevant action for button if (e.CommandName == "Edit") { DataGrid1.EditItemIndex=e.Item.ItemIndex; DataGrid1.DataBind(); }Label15.Text="Edit"; }
But nothing happens. Ive even put in a test bit of code to indicate via a label if the DataGrid1_ItemCommand is called. But it doesnt work, so obviously its not being activated. Any ideas why??? Ive putDataGrid1_ItemCommand
in the appropriate DataGrid properties option. I need help! Thanks!!! -
Hi, Im using a DataGrid to display some info from the DB. Instead of the standard edit column i created a template column, with a button in it. If i use a Linkbutton it all works fine. However if i use a standard button nothing happens. Ive given the button a CommandName of Edit, and under the ItemCommand ive got:
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { //performs relevant action for button if (e.CommandName == "Edit") { DataGrid1.EditItemIndex=e.Item.ItemIndex; DataGrid1.DataBind(); }Label15.Text="Edit"; }
But nothing happens. Ive even put in a test bit of code to indicate via a label if the DataGrid1_ItemCommand is called. But it doesnt work, so obviously its not being activated. Any ideas why??? Ive putDataGrid1_ItemCommand
in the appropriate DataGrid properties option. I need help! Thanks!!!Try this, you take a button column and then turn it the template column. This will be done.
-
Try this, you take a button column and then turn it the template column. This will be done.
Ok, i forgot to put the binding code inside
!PostBack
so it was just reloading the data, and not appearing to change to edit mode. However, now my problem is that when i click to enter 'edit' mode the all the Data / DataGrid disappears except for the Header. Why is this? I even tried using a DataList instead and this does the same. Im obviously missing something. HELPPPPPPPPPPPPPPPPPPP!!!! -
Ok, i forgot to put the binding code inside
!PostBack
so it was just reloading the data, and not appearing to change to edit mode. However, now my problem is that when i click to enter 'edit' mode the all the Data / DataGrid disappears except for the Header. Why is this? I even tried using a DataList instead and this does the same. Im obviously missing something. HELPPPPPPPPPPPPPPPPPPP!!!!