Showing posts with label delete. Show all posts
Showing posts with label delete. Show all posts

Wednesday, March 28, 2012

Modal Popup Delete Help.

Im working on a gridview that`ll delete a row of data. Currently the gridview shows the data, and i have a linkbutton at the other end of the gridviews template field. When you click the linkbutton the modalpopup appears and it has two buttons "cancel" and "ok". Cancel makes it disappear, and ok, doesnt do its job lol. I have a foreach code that deletes all the entries to the gridview but i cant work out what the individual row delete code would be! my gridview code is :

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="Admin" BorderStyle="Dotted" BorderWidth="0px" ShowHeader="False" DataKeyNames="UserID">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="Admin" runat="server" >

<table width="630">
<tr>
<td width="460">
<div align="left">
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("UserID", "~/Profile.aspx?id={0}") %>' Text='<%# Eval("FullName") %>' Font-Names="Tahoma" Font-Size="10pt" ForeColor="SteelBlue"></asp:HyperLink>
</div>
</td>
<td>
<div align="right">
<asp:LinkButton ID="LinkButton7" runat="server" Font-Names="Tahoma" Font-Size="8pt" ForeColor="SteelBlue" OnClick="LinkButton7_Click">Remove</asp:LinkButton>
</div>
</td>
</tr>
</table>
<hr />
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender5" TargetControlID="LinkButton7" CancelControlID="Button10" PopupControlID="Panel5" runat="server" BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
<asp:Label ID="Label17" Visible="false" runat="server"></asp:Label>
<asp:Panel ID="Panel5" runat="server" Width="300px" BackColor="IndianRed">
<asp:Label ID="Label18" runat="server" Text="Are you sure you want to delete this person?"></asp:Label><asp:Label ID="Label19" runat="server"></asp:Label>
<table>
<tr>
<td>
<asp:Button ID="Button9" runat="server" OnClick="LinkButton9_Click" Text="Confirm" />
</td>
<td>
<asp:Button ID="Button10" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
Nothing...

</EmptyDataTemplate>
</asp:GridView>

Currently when the linkbutton9 is clicked... it loop though all of the records and deletes them can someone help me with a code that deletes the unique ID in the list of users "UserIDNumber" thanks in advance! si!

Hiblink18jew,

You don't need to loop though all of the records to find out the record that you want to delete.

Just change:

<asp:Button ID="Button9" runat="server" OnClick="LinkButton9_Click" Text="Confirm" />

to:

<asp:Button ID="Button9" runat="server" OnCommand="LinkButton9_Command" CommandArgument='<%# Eval("UserID", "{0}") %>' Text="Confirm" />

C# code:

protected void LinkButton9_Command(object sender, CommandEventArgs e)
{
// delete the person whoes UserID is e.CommandArgument
}

Best Regards

Modal Popup Delete

Hey, I have a gridview with a linkbutton "delete". I made this originally with a rowcommand that deleted the item associated with that row. I am now implementing a modal pop-up to confirm deleteing the row of data. The pop-upworks fine, and appears when i click the linkbutton ( note the link button now has no "onclick" event ) the popup panel has two buttons inside it button1 and button2, 1 = confirm, 2 = cancel.

I set the CommandArguement of button1 to the ID of the item, and the CommandName to "DeleteMe". The command_row event is :

protected void GridView6_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DeleteMe")
{
SqlCommand DeleteIt = new SqlCommand("DELETE FROM Items WHERE ItemD = '" + e.CommandArgument + "'", Connection);
Connection.Open();
DeleteIt.ExecuteNonQuery();
Connection.Close();
GridView6.DataBind();
}
}

When the user clicks button1 nothing happens.. im a little bit confused as to why, can anyone help? i assumed as the ajax extender is within the gridview row it would just continue to be a row command? if im way off can someone please let me know, thanks a million John

does anyone have an ideas? sorry to be a bit pushy but its driving me insane! lol, Ive done some random google searches and in the forums and i couldnt find anything, thanks John

Monday, March 26, 2012

Modal Popup In A Repeater

Hi,

Is there a way to use the ModalPopupExtender from inside a repeater -- each item would have a "delete" link button, and on clicking this, the Panel should be shown? Ive tried everything I can think of, but am not getting anywhere.

Thanks

Joe

Hmmm, I have seen modalpopupextender in the repeater before and it worked fine. Do you get any javascript errors, run-time errors about the extender setup, and how are you wiring the extender to the actual button that will cause the pop up to appear?


The ToolkitTests\Manual\DataboundDynamicPopulate.aspx file that comes with the Toolkit includes a ModalPopup in a repeater (DataList).


Thanks for the heads up. Between this and another article I found (sorry, cant find it right now to give credit), I came up with the solution I was looking for.

My solution is here (for my future reference): http://blog.joelowrance.com/archive/2007/07/10/ajax-modalpopupextender-in-a-repeater.aspx