///*******************HtML
<asp:GridView DataKeyNames="CategoryID" ID="GridView1"
runat="server" AutoGenerateColumns="False"
OnRowCommand="GridView1_RowCommand"
OnRowDataBound="GridView1_RowDataBound"
>
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("ID")
%>'
CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
//******************RowDataBound
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lb = (LinkButton)e.Row.FindControl("LnkDel");
lb.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete this record " +
DataBinder.Eval(e.Row.DataItem, "ID") + "')");
}
}
//******************** RowCommand
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
// get the ID of the clicked row
int ID = Convert.ToInt32(e.CommandArgument);
// Delete the record
DeleteRecordByID(ID);
// Implement this on your own :)
}
}
//*****************or Button Click
No comments:
Post a Comment