Ti posto un esempio, qui uso due pulsanti, uno per editare, e uno per cancellare, come CommandName uso "Edit" e "Del". OnItemCommand indica il gestore di eventi.
Il codice per l'edit o per il del (o per quello che vuoi) ovviamente dipende da quello che devi fare.
pagina aspx:
codice:
<asp:DataGrid id="DataGridAuth" runat="server" AutoGenerateColumns="False" OnItemCommand="DataGridAuth_ItemCommand" DataKeyField="DataKey">
....
<Columns>
...
<asp:ButtonColumn CommandName="Detail" Text=">>" HeaderText="Edit Rigths"></asp:ButtonColumn>
<asp:ButtonColumn CommandName="Del" Text=">>" HeaderText="Delete Relations"></asp:ButtonColumn>
</Columns>
</datagrid>
codice c#:
codice:
protected void DataGridAuth_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string id=((DataGrid)source).DataKeys[e.Item.ItemIndex].ToString()
switch (e.CommandName.ToString())
{
case "Detail":
//Codice per mostrare il dettaglio
break;
case "Del":
//Codice per del
break;
}
}