protected void gvGroups_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditRow") { //Retrieve the row index stored in the //CommandArgument property. int index = Convert.ToInt32(e.CommandArgument); // Retrieve the row that contains the button // from the Rows collection. GridViewRow row = gvGroups.Rows[index]; IDholder.Text = row.Cells[0].Text; tbxOldName.InnerText = row.Cells[1].Text; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(@"<script type='text/javascript'>"); sb.Append("$('#modalShowGroupDetails').modal('show');"); sb.Append(@"</script>"); ScriptManager.RegisterStartupScript(this, this.GetType(), "ModalScript", sb.ToString(), false); } if (e.CommandName == "Delet") { GroupsConRepository repgpCon = new GroupsConRepository(); GroupsRepository repgp = new GroupsRepository(); // Retrieve the row index stored in the // CommandArgument property. int index = Convert.ToInt32(e.CommandArgument); // Retrieve the row that contains the button // from the Rows collection. GridViewRow row = gvGroups.Rows[index]; int id = row.Cells[0].Text.ToInt(); List <int> subIDs = repgp.getSubGroupsIDByFatherID(id).ToList(); if (repgpCon.DeleteConsBySubGroupIdList(subIDs)) { if (repgp.DelSubGruop(subIDs)) { if (repgp.DelGruop(id)) { gvGroups.DataSource = null; gvGroups.DataBind(); ddlGroups.DataSource = null; ddlGroups.DataBind(); gvSubGroups.DataSource = null; gvSubGroups.DataBind(); DataTable allGroups = new DataTable(); allGroups = repgp.LoadAllGroups(); ddlgroupsForModal.DataSource = allGroups; ddlgroupsForModal.DataTextField = "Title"; ddlgroupsForModal.DataValueField = "GroupID"; ddlgroupsForModal.DataBind(); ddlgroupsForModal.Items.Insert(0, new ListItem("یکی از گروه ها را انتخاب کنید", "-2")); gvGroups.DataSource = allGroups; gvGroups.DataBind(); ddlGroups.DataSource = allGroups; ddlGroups.DataTextField = "Title"; ddlGroups.DataValueField = "GroupID"; ddlGroups.DataBind(); ddlGroups.Items.Insert(0, new ListItem("همه زیر گروه ها", "-2")); gvSubGroups.DataSource = repgp.LoadAllSubGroups(); gvSubGroups.DataBind(); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با موفقیت انجام شد');", true); } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با خطا مواجه شد ، بعدا سعی کنید یا با پشتیبانی تماس بگیرید!');", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با خطا مواجه شد ، بعدا سعی کنید یا با پشتیبانی تماس بگیرید!');", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با خطا مواجه شد ، بعدا سعی کنید یا با پشتیبانی تماس بگیرید!');", true); } } }