日期:2014-05-18  浏览次数:20572 次

DataGrid 按钮列 删除功能怎么实现
就是里面的按纽列里有个 删除中  然后怎么实现删除该行的功能!!!

------解决方案--------------------
// .aspx
<asp:DataGrid ID= "DataGrid1 " DataKeyField= "ID " runat= "server " OnDeleteCommand= "DataGrid1_DeleteCommand ">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID= "btnDelete " runat= "server " CausesValidation= "false " CommandName= "Delete " Text= "Delete " OnClientClick= "if(!confirm( 'deleting? ')) return false; "> </asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

// .aspx.cs
protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
{
// 获取 ID
object id = DataGrid1.DataKeys[e.Item.ItemIndex];
// 执行删除
// ...
// ...
// 重新绑定数据
// ...
}