Add a GridView (after binding a data source to it)-> (on the design page) edit-
> Add template-> set attributes of the column template-> return
-> Edit template-> Add a Linkbutton-> set Text to delete
> Set the CommandName attribute (for example, CommandName = "Delete ")
-> Set the CommandArgument value {for example, CommandArgument = '<% # Bind ("stuNO ")}
> Add the RowCommand event of the GridView.
Code:
Webpage Design Code:
<Asp: TemplateField ShowHeader = "False">
<ItemTemplate>
<Asp: LinkButton ID = "LinkButton1" runat = "server" CausesValidation = "False"
CommandName = "Delete" Text = "Delete" OnClick = "return confirm ('Do you want to Delete data? ') "CommandArgument =' <% # Bind (" stuNO ") %> '> </asp: LinkButton>
</ItemTemplate>
</Asp: TemplateField>
Main background code:
Protected void GridView1_RowCommand (object sender, GridViewCommandEventArgs e)
{
If (e. CommandName = "Delete") // if the button is deleted
{
String stuNO = e. CommandArgument. ToString (); // obtain the student ID.
Int result = stuBll. delStudent (stuNO); // use a three-tier architecture to call the method at the business logic layer.
If (result> 0)
{
Response. Write ("deleted successfully! ");
}
Else
{
Response. Write ("deletion failed! ");
}
GvBind (); // rebind data after deletion
}
}
Author: ruiying