List<Facade.File> up = new List<Facade.File>();
up = FilesQueries.GetAllFiles(SessionManager.AuthenticatedUser, Id);
grdFiles.DataSource = up;
grdFiles.DataBind();
protected void grdFiles_ItemCommand(object sender, GridViewCommandEventArgs e)
{
LinkButton lnkBtn = (LinkButton)e.CommandSource; // the button
GridViewRow myRow = (GridViewRow)lnkBtn.Parent.Parent; // the row
GridView myGrid = (GridView)sender; // the gridview
int ID = Convert.ToInt32(myGrid.DataKeys[myRow.RowIndex].Value.ToString());
switch (e.CommandName)
{ case "DeleteIt":
// need to confirm delete
bool success = Facade.FilesTransaction.DeleteFile(SessionManager.AuthenticatedUser, ID);
break;
default:
break;
I'm doing going to search the web some more, maybe I need to change the way I'm creating my grid view.
CraigGiles
Member
22 Points
22 Posts
Confirmation on DataGrid "Delete" LinkButton
Feb 26, 2013 10:03 PM|LINK
Not sure there is a solution out there for the way I'm creating my gridview but I need to have the user confirm deleting the record.
<asp:GridView ID="grdFiles" runat="server" skin="Default" DataKeyNames="DocId" AutoGenerateColumns="false" OnRowCommand="grdFiles_ItemCommand"> <Columns> <asp:BoundField DataField="DocId" HeaderText="ID" Visible="false" /> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="lnkbtnView" runat="server" CommandName="View" Width="50px" ForeColor="Red" CausesValidation="False" Text="View"> </asp:LinkButton> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="FileNames" HeaderText="File Name" /> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="lnkbtnDelete" runat="server" CommandName="DeleteIt" Width="50px" ForeColor="Red" CausesValidation="False" Text="Delete"> </asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>List<Facade.File> up = new List<Facade.File>(); up = FilesQueries.GetAllFiles(SessionManager.AuthenticatedUser, Id); grdFiles.DataSource = up; grdFiles.DataBind();protected void grdFiles_ItemCommand(object sender, GridViewCommandEventArgs e) { LinkButton lnkBtn = (LinkButton)e.CommandSource; // the button GridViewRow myRow = (GridViewRow)lnkBtn.Parent.Parent; // the row GridView myGrid = (GridView)sender; // the gridview int ID = Convert.ToInt32(myGrid.DataKeys[myRow.RowIndex].Value.ToString()); switch (e.CommandName) { case "DeleteIt": // need to confirm delete bool success = Facade.FilesTransaction.DeleteFile(SessionManager.AuthenticatedUser, ID); break; default: break;I'm doing going to search the web some more, maybe I need to change the way I'm creating my grid view.
oned_gk
All-Star
30915 Points
6326 Posts
Re: Confirmation on DataGrid "Delete" LinkButton
Feb 26, 2013 10:25 PM|LINK
vinz
All-Star
126896 Points
17922 Posts
MVP
Re: Confirmation on DataGrid "Delete" LinkButton
Feb 26, 2013 10:57 PM|LINK
Typically the javascript confirm will be used to prompt the user and there are many possible ways to implement it in gridview. Here's a step by step example of different options: http://geekswithblogs.net/dotNETvinz/archive/2009/02/22/display-confirmation-message-on-gridview-deleting.aspx
If you want more fancy then you can try out this opensource control: MessageBox controls for WebForms. And here's a simple demo: http://geekswithblogs.net/dotNETvinz/archive/2012/02/01/using-proudmonkey-confirmbox-control-in-gridview.aspx
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
CraigGiles
Member
22 Points
22 Posts
Re: Confirmation on DataGrid "Delete" LinkButton
Feb 27, 2013 12:57 AM|LINK