Deleting a row in datagrid view

前端 未结 5 709
情歌与酒
情歌与酒 2021-01-26 06:33

I want to Delete a row in the Gridview which is in the update panel . But instead of the command button ., i took a link button to get a confirmation message. Now if I press ok

5条回答
  •  时光取名叫无心
    2021-01-26 07:16

    you can use RowCommand event of gridview, like...

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {            
            e.CommandArgument  -- this return Data Key Value
    //Deletion Code goes here.....
    var brochureToDelete = (from b in dataContext.ArticleBrochures where b.ArticleId == ArticleId select b).FirstOrDefault(); 
    if (brochureToDelete != null) 
    { 
    dataContext.ArticleBrochures.DeleteOnSubmit(brochureToDelete);
    dataContext.SubmitChanges(); 
    bindBrochureGridView(ArticleId);
    // if your gridview in updatepanel
    //Call update method of UpdatePanel
    //UpdatePanel.Update();
     }
    }
    

提交回复
热议问题