Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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">
- <Columns>
- <asp:TemplateField ShowHeader="false">
- <ItemTemplate>
- <asp:Button ID="ButtonEdit" runat="server" CssClass="btn btn-success" CausesValidation="false" CommandName="EditData"
- Text="Edit" CommandArgument="<%# ((GridViewRow) Container).RowIndex%>" Width="100px" Visible="true" />
- <asp:Button ID="ButtonDelete" runat="server" CssClass="btn btn-danger" CausesValidation="false" CommandName="DeleteData"
- Text="Delete" CommandArgument="<%# ((GridViewRow) Container).RowIndex%>" Width="100px" OnClientClick="return confirm('Are you sure you want to delete the user?');" Visible="true" />
- <asp:Button ID="ButtonConfirmEdit" runat="server" CssClass="btn btn-primary" CausesValidation="false" CommandName=""
- Text="Confirm" CommandArgument="<%# ((GridViewRow) Container).RowIndex%>" Width="100px" OnClientClick="return confirm('Are you sure you want to edit the user data?');" Visible="false" />
- <asp:Button ID="ButtonCancelEdit" runat="server" CssClass="btn btn-danger" CausesValidation="false" CommandName=""
- Text="Cancel" CommandArgument="<%# ((GridViewRow) Container).RowIndex%>" Width="100px" Visible="false" />
- </ItemTemplate>
- </asp:TemplateField>
- protected void GridViewTotal_RowCommand(object sender, GridViewCommandEventArgs e)
- {
- if (e.CommandName == "EditData")
- {
- int index = Convert.ToInt32(e.CommandArgument);
- GridViewTotal.EditIndex = index;
- GridViewTotal_UpdateEditButtons(index, "edit");
- GridViewTotal.DataBind();
- }
- }
- protected void GridViewTotal_UpdateEditButtons(int index, string arg)
- {
- Button btnConfirm = (Button)GridViewTotal.Rows[index].FindControl("ButtonConfirmEdit");
- Button btnCancel = (Button)GridViewTotal.Rows[index].FindControl("ButtonCancelEdit");
- Button btnEdit = (Button)GridViewTotal.Rows[index].FindControl("ButtonEdit");
- Button btnDelete = (Button)GridViewTotal.Rows[index].FindControl("ButtonDelete");
- if(arg == "edit")
- {
- btnDelete.Visible = false;
- btnEdit.Visible = false;
- btnConfirm.Visible = true;
- btnCancel.Visible = true;
- }
- else if(arg == "confirm")
- {
- btnDelete.Visible = true;
- btnEdit.Visible = true;
- btnConfirm.Visible = false;
- btnCancel.Visible = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement