datagrid linkbutton
DataGrid控件部分代码
<Columns> <asp:TemplateColumn>
<HeaderTemplate>
<FONT face="宋体"></FONT>
</HeaderTemplate>
<ItemTemplate>
<FONT face="宋体"> </FONT>
<asp:LinkButton runat="server" Text="Modify" CommandArgument='<%# ((System.Data.DataRowView)Container.DataItem)["user_id"] %>' CommandName="Modify">
<img border="0" src="images/button_modify.gif"></asp:LinkButton>
<asp:LinkButton runat="server" Text="Delete" CommandArgument='<%# ((System.Data.DataRowView)Container.DataItem)["user_id"] %>' CommandName="Delete">
<img border="0" src="images/button_delete.gif" onClick=" confirm('删除操作不可恢复,确认吗?');}"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
/// <summary>
/// 更新、删除按钮按下事件
/// </summary>
private void DataList_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
LinkButton b= (LinkButton)e.CommandSource;
switch (b.CommandName)
{
case "Modify" :
this.Response.Redirect("User.aspx?id="+b.CommandArgument);
break;
case "Delete" :
TCmsUser cdata = new TCmsUser();
TCmsUser.DeleteByID(b.CommandArgument);//删除函数
RefreshList();//刷新列表函数
break;
}
}