Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. <asp:GridView ID="GridViewTotal" runat="server" CssClass="list-group-item table-condensed table-hover table-responsive" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="false" DataKeyNames="Id" DataSourceID="SqlDSAdminTable" OnRowCommand="GridViewTotal_RowCommand" OnRowUpdating="GridViewTotal_RowUpdating">
  2. <Columns>
  3. <asp:TemplateField ShowHeader="false">
  4. <ItemTemplate>
  5. <asp:Button ID="ButtonEdit" runat="server" CssClass="btn btn-success" CausesValidation="false" CommandName="EditData"
  6. Text="Edit" CommandArgument="<%# ((GridViewRow) Container).RowIndex%>" Width="100px" Visible="true" />
  7. <asp:Button ID="ButtonDelete" runat="server" CssClass="btn btn-danger" CausesValidation="false" CommandName="DeleteData"
  8. Text="Delete" CommandArgument="<%# ((GridViewRow) Container).RowIndex%>" Width="100px" OnClientClick="return confirm('Are you sure you want to delete the user?');" Visible="true" />
  9. <asp:Button ID="ButtonConfirmEdit" runat="server" CssClass="btn btn-primary" CausesValidation="false" CommandName=""
  10. Text="Confirm" CommandArgument="<%# ((GridViewRow) Container).RowIndex%>" Width="100px" OnClientClick="return confirm('Are you sure you want to edit the user data?');" Visible="false" />
  11. <asp:Button ID="ButtonCancelEdit" runat="server" CssClass="btn btn-danger" CausesValidation="false" CommandName=""
  12. Text="Cancel" CommandArgument="<%# ((GridViewRow) Container).RowIndex%>" Width="100px" Visible="false" />
  13. </ItemTemplate>
  14. </asp:TemplateField>
  15.  
  16. protected void GridViewTotal_RowCommand(object sender, GridViewCommandEventArgs e)
  17. {
  18. if (e.CommandName == "EditData")
  19. {
  20. int index = Convert.ToInt32(e.CommandArgument);
  21. GridViewTotal.EditIndex = index;
  22. GridViewTotal_UpdateEditButtons(index, "edit");
  23. GridViewTotal.DataBind();
  24.  
  25.  
  26. }
  27. }
  28.  
  29. protected void GridViewTotal_UpdateEditButtons(int index, string arg)
  30. {
  31. Button btnConfirm = (Button)GridViewTotal.Rows[index].FindControl("ButtonConfirmEdit");
  32. Button btnCancel = (Button)GridViewTotal.Rows[index].FindControl("ButtonCancelEdit");
  33. Button btnEdit = (Button)GridViewTotal.Rows[index].FindControl("ButtonEdit");
  34. Button btnDelete = (Button)GridViewTotal.Rows[index].FindControl("ButtonDelete");
  35.  
  36. if(arg == "edit")
  37. {
  38. btnDelete.Visible = false;
  39. btnEdit.Visible = false;
  40. btnConfirm.Visible = true;
  41. btnCancel.Visible = true;
  42. }
  43. else if(arg == "confirm")
  44. {
  45. btnDelete.Visible = true;
  46. btnEdit.Visible = true;
  47. btnConfirm.Visible = false;
  48. btnCancel.Visible = false;
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement