what i did When delete button press its goes rowcommand event then i check is it delete button press. then i re -create the datasource which not included the deleted row and rebind the gridview. but Now i want to delete the record also from the database.
Thats why i want a confirmation dialog box for deleting the record from the database.
shahid.majee...
Member
620 Points
543 Posts
Implementing Ajax Model Popup Extender in gridview for Delete Button Confirmation
Feb 20, 2012 08:36 AM|LINK
Hi I want to implement Model Popup Extender in gridivew for confirmation before row to be deleted from the Gridview.
But its give me the error Here is Error.
Here is ASPX Code
<asp:GridView ID="gvRoomList" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" onrowcommand="gvRoomList_RowCommand" onrowdeleting="gvRoomList_RowDeleting" HeaderStyle-BackColor="#506272" HeaderStyle-ForeColor="White"> <Columns> <asp:BoundField DataField="ID" HeaderText="ID" /> <asp:BoundField DataField="RoomID" HeaderText="Rum" /> <asp:BoundField DataField="RoomNamn" HeaderText="Namn" /> <asp:BoundField DataField="Huvudrum" HeaderText="Huvudrum" /> <asp:BoundField DataField="Kontor" HeaderText="Kontor" /> <asp:BoundField DataField="Datum" DataFormatString="{0:d}" HeaderText="Datum" /> <asp:BoundField DataField="Fran" HeaderText="Fran" /> <asp:BoundField DataField="Till" HeaderText="Till" /> <asp:TemplateField HeaderText="Action" ShowHeader="False"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="Delete" Text="tabort"></asp:LinkButton> <asp:ModalPopupExtender ID="LinkButton1_ModalPopupExtender" runat="server" DynamicServicePath="" Enabled="True" TargetControlID="LinkButton1" PopupControlID="Panel1" BackgroundCssClass="modalBackground" DropShadow="true"> </asp:ModalPopupExtender> </ItemTemplate> </asp:TemplateField> </Columns> <HeaderStyle Font-Names="Arial" Font-Size="11px" Font-Bold="True" /> <RowStyle Font-Names="Arial" Font-Size="11px" /> </asp:GridView> <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none" Width="233px"> <p align="center">Are you Sure to delete this room</p> <br /> <div align="center"> <asp:Button ID="BtnOk" runat="server" Text="OK" onclick="gvRoomList_RowCommand" /> <asp:Button ID="BtnCancel" runat="server" Text="Cancel" onclick="BtnCancel_Click" /> </div> </asp:Panel>Shahid Majeed
Email: shahid.majeed@gmail.com
dinesh kumar...
Participant
986 Points
247 Posts
Re: Implementing Ajax Model Popup Extender in gridview for Delete Button Confirmation
Feb 20, 2012 08:44 AM|LINK
Have you used the rowcomand event to write the code for delete??
Jai Jagannath
shahid.majee...
Member
620 Points
543 Posts
Re: Implementing Ajax Model Popup Extender in gridview for Delete Button Confirmation
Feb 20, 2012 08:51 AM|LINK
what i did When delete button press its goes rowcommand event then i check is it delete button press. then i re -create the datasource which not included the deleted row and rebind the gridview. but Now i want to delete the record also from the database. Thats why i want a confirmation dialog box for deleting the record from the database.
Here Is my Code
protected void gvRoomList_RowCommand(object sender, GridViewCommandEventArgs e) { if(e.CommandName == "Delete") { int ID; ID = Convert.ToInt32(gvRoomList.DataKeys[Convert.ToInt32(e.CommandArgument)]["ID"]); DeleteRoom(ID); } } protected void DeleteRoom(int ID) { try { if (this.ViewState["RoomList"] != null) { DataTable dtRoom = new DataTable(); DataRow dr = null; Boolean flag = false; int Counter = 0; dtRoom.Columns.Add(new DataColumn("ID", typeof(string))); dtRoom.Columns.Add(new DataColumn("RoomID", typeof(string))); dtRoom.Columns.Add(new DataColumn("RoomNamn", typeof(string))); dtRoom.Columns.Add(new DataColumn("Kontor", typeof(string))); dtRoom.Columns.Add(new DataColumn("Datum", typeof(string))); dtRoom.Columns.Add(new DataColumn("Fran", typeof(string))); dtRoom.Columns.Add(new DataColumn("Till", typeof(string))); dtRoom.Columns.Add(new DataColumn("HuvudRum", typeof(string))); for (int i = 0; i < gvRoomList.Rows.Count; i++) { if (Convert.ToInt32(gvRoomList.Rows[i].Cells[0].Text) != ID) { dr = dtRoom.NewRow(); dr["ID"] = Counter.ToString(); dr["RoomID"] = gvRoomList.Rows[i].Cells[1].Text; dr["RoomNamn"] = gvRoomList.Rows[i].Cells[2].Text; Response.Write("space"+gvRoomList.Rows[i].Cells[3].Text); if (gvRoomList.Rows[i].Cells[3].Text == " ") dr["HuvudRum"] = ""; else dr["HuvudRum"] = gvRoomList.Rows[i].Cells[3].Text; if (gvRoomList.Rows[i].Cells[3].Text == "Huvudrum") flag = false; dr["Kontor"] = gvRoomList.Rows[i].Cells[4].Text; dr["Datum"] = gvRoomList.Rows[i].Cells[5].Text; dr["Fran"] = gvRoomList.Rows[i].Cells[6].Text; dr["Till"] = gvRoomList.Rows[i].Cells[7].Text; dtRoom.Rows.Add(dr); Counter+=1; }else { ddRoomList.SelectedValue = gvRoomList.Rows[i].Cells[1].Text; txtDateFrom.Text =string.Format("{0:d}",gvRoomList.Rows[i].Cells[5].Text); ddStartTime.SelectedValue = gvRoomList.Rows[i].Cells[6].Text.Replace(".",":"); ddEndTime.SelectedValue = gvRoomList.Rows[i].Cells[7].Text.Replace(".", ":"); if(gvRoomList.Rows[i].Cells[3].Text == "Huvudrum") { flag = true; } //// Database Connection //Connection Conn = new Connection(); //Conn.OledbConntion(); //Conn.OpenOledbConnection(); //// Delete Query //string SQL = "Delete From RumBokBokning Where RumID=" + gvRoomList.Rows[i].Cells[1].Text + " and Datum= '" + gvRoomList.Rows[i].Cells[5].Text + "' and Fran="; //Conn.CloseOledbConnection(); } } this.ViewState["RoomList"] = dtRoom; gvRoomList.DataSource = dtRoom; gvRoomList.DataBind(); if (flag == true) chHuvudrum.Visible = true; lbRoomStatus.Visible = false; } } catch(Exception exc) { lbmsg.Text = exc.Message.ToString(); lbmsg.Visible = true; } } protected void gvRoomList_RowDeleting(object sender, GridViewDeleteEventArgs e) { }Shahid Majeed
Email: shahid.majeed@gmail.com
chetan.sarod...
All-Star
65619 Points
11118 Posts
Re: Implementing Ajax Model Popup Extender in gridview for Delete Button Confirmation
Feb 21, 2012 02:02 AM|LINK
Hi, Please refer this
http://mattberseth.com/blog/2007/07/confirm_gridview_deletes_with.html
http://yasserzaid.wordpress.com/2009/03/27/ajax-modal-popup-extender-to-delete-with-confirmation-from-gridview/
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.