Friday 30 May 2014

Delete Confirmation inside gridview delete on Client Side in asp.net



///*******************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

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...