I want to get a modal pop up when one delete link button in a gridview is clicked.
I have tried to solve this by myself without any success. Anyone with any suggestion?
public void deleteRow(Object sender, GridViewDeleteEventArgs e)
{
long id = (long)Gridview_Rooms.DataKeys[e.RowIndex].Value;
RoomVO room = new RoomVO();
room.Id = id;
roomService.DeleteRoom(room);
<asp:GridViewID="GridView1"runat="server"DataSourceID="SqlDataSource1"AutoGenerateColumns="False"DataKeyNames="EmployeeId"><Columns><asp:TemplateFieldHeaderText="Delete"><ItemTemplate><asp:ButtonID="btnDelete"Text="Delete"runat="server"OnClientClick="return confirm('Are you sureyou want to delete this record?');"CommandName="Delete"/></ItemTemplate></asp:TemplateField><asp:BoundFieldHeaderText="EmployeeId"DataField="EmployeeId"/><asp:BoundFieldHeaderText="FirstName"DataField="FirstName"/><asp:BoundFieldHeaderText="LastName"DataField="LastName"/></Columns></asp:GridView>
Yes I have. But I want to use modal pop up in stead to make it more dynamically and to don't let user clicking on anything else before answering on the question...
If you change the commandname on the delete button to "Select" then you can popup the modal window on the gridviews selectedindexchanged event by calling the modalpopup1.Show() method. Then when the user click the "OK" or "Delete" button (or whatever button
the user must click to confirm they want to proceed with the delete command) in the modalpopup, attach that to a server side event (if you have this as a button ans it is attached to the OKButtonID of the modalpopup, then you will want to change the usesubmitbehavior
property to "False" so it will fire the server side event, not the client side event.). Inside this event do the deleteing of the row, using the gridview.selectedvalue.
TheGh0st
Member
162 Points
85 Posts
Gridview: Modal PopUp Deleting confirmbox
Dec 25, 2006 01:12 PM|LINK
I want to get a modal pop up when one delete link button in a gridview is clicked.
I have tried to solve this by myself without any success. Anyone with any suggestion?
Here is my gridview code:
<asp:UpdatePanel ID="p1" runat="server">
<ContentTemplate>
<asp:GridView
ID="Gridview_Rooms"
runat="server"
DataKeyNames="Id"
SkinID="GridView1"
OnSelectedIndexChanged="editRow"
OnRowDeleting="deleteRow"
OnRowDataBound="rowDataBound">
<Columns>
<asp:BoundField
HeaderText="Room number"
DataField="RoomNr">
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField
HeaderText="Roomtype"
DataField="RoomtypeName">
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField
HeaderText="Max persons"
DataField="MaxTotalPersons">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField ShowHeader="False">
<ItemStyle HorizontalAlign="Right" />
<ItemTemplate>
<asp:LinkButton
ID="EditButton"
runat="server"
CommandName="Select">Edit</asp:LinkButton>
<asp:LinkButton
ID="DeleteButton"
runat="server"
CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Here is the codebehind:
pkellner
All-Star
24018 Points
3616 Posts
ASPInsiders
Moderator
MVP
Re: Gridview: Modal PopUp Deleting confirmbox
Dec 25, 2006 02:46 PM|LINK
have you tried the javascript approach?
<asp:GridView ID="GridView1"runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="EmployeeId"> <Columns> <asp:TemplateField HeaderText="Delete"> <ItemTemplate> <asp:Button ID="btnDelete" Text="Delete" runat="server" OnClientClick="return confirm('Are you sureyou want to delete this record?');" CommandName="Delete" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="EmployeeId" DataField="EmployeeId" /> <asp:BoundField HeaderText="FirstName" DataField="FirstName" /> <asp:BoundField HeaderText="LastName" DataField="LastName" /> </Columns> </asp:GridView>From: http://aspalliance.com/786http://peterkellner.net
Microsoft MVP • ASPInsider
TheGh0st
Member
162 Points
85 Posts
Re: Gridview: Modal PopUp Deleting confirmbox
Dec 25, 2006 02:50 PM|LINK
aquillin
Participant
1465 Points
268 Posts
Re: Gridview: Modal PopUp Deleting confirmbox
Dec 25, 2006 03:32 PM|LINK
If you change the commandname on the delete button to "Select" then you can popup the modal window on the gridviews selectedindexchanged event by calling the modalpopup1.Show() method. Then when the user click the "OK" or "Delete" button (or whatever button the user must click to confirm they want to proceed with the delete command) in the modalpopup, attach that to a server side event (if you have this as a button ans it is attached to the OKButtonID of the modalpopup, then you will want to change the usesubmitbehavior property to "False" so it will fire the server side event, not the client side event.). Inside this event do the deleteing of the row, using the gridview.selectedvalue.
Hope this helps.
-Alan
TheGh0st
Member
162 Points
85 Posts
Re: Gridview: Modal PopUp Deleting confirmbox
Dec 25, 2006 05:47 PM|LINK
Hey Alan!
Thanks for you help! I'm not sure that I understand all your instruction, so could you please give me a example on how you mean to do this?
Tnx again!
aquillin
Participant
1465 Points
268 Posts
Re: Gridview: Modal PopUp Deleting confirmbox
Dec 26, 2006 05:19 PM|LINK
Change your delete linkbutton to this:
<asp:LinkButton
ID="DeleteButton"
runat="server"
CommandName="Select">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
then on the code beside page, you will need to create an event handler for the gridview like so:
C#
protected
void Gridview1_SelectedIndexChanged(object sender, EventArgs e){
Modalpopup1.Show();
}
or
VB
Protected Sub Gridview1_SelectedIndexChanged(ByVal sender as object, ByVal e as EventArgs)
Modalpopup1.Show()
End Sub
This will popup the modal window. Then you will need to do the delete command from a button event that is click from within the modal window.
Protected Sub Button1_Click(ByVal sender as object, ByVal e as EventArgs)
Dim id as int32 = gridview1.SelectedValue
'do delete action.
End Sub
Hope that helps.
Master Pages
TheGh0st
Member
162 Points
85 Posts
Re: Gridview: Modal PopUp Deleting confirmbox
Dec 26, 2006 07:19 PM|LINK
LurkingVariable
Member
74 Points
43 Posts
Re: Gridview: Modal PopUp Deleting confirmbox
Jan 22, 2007 09:06 AM|LINK