prevent a file from being deleted unless its selected first

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 41
Reputation: julseypart is an unknown quantity at this point 
Solved Threads: 0
julseypart julseypart is offline Offline
Light Poster

prevent a file from being deleted unless its selected first

 
0
  #1
Mar 1st, 2009
hi all.
ok i have been able to create an error message - if the user tries to delete a row which has not been selected first; but it still deletes from the gridview...

  1. void DeleteRowButton_Click(Object sender, EventArgs e)
  2. {
  3.  
  4. LinkButton btn = sender as LinkButton;
  5. GridViewRow row = btn.NamingContainer as GridViewRow;
  6.  
  7.  
  8. if (row == GridView1.SelectedRow) {
  9. GridView1.DeleteRow(GridView1.SelectedIndex);
  10.  
  11. // delete file from server
  12.  
  13. }
  14.  
  15. else
  16.  
  17. lblDeleteResult.Text = "Please select this file first, if you wish to delete it";
  18.  
  19.  
  20.  
  21.  
  22. }


but the asp.net delete command- Delete="Delete From tbl....Where.......etc" deletes the file from the gridview regardless. How can one prevent the delete command from running unless the row is selected first?

p.s. the delete command is specified in the .aspx file

thanks
Last edited by julseypart; Mar 1st, 2009 at 9:47 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 68
Reputation: srikanthkadem is an unknown quantity at this point 
Solved Threads: 11
srikanthkadem srikanthkadem is offline Offline
Junior Poster in Training

Re: prevent a file from being deleted unless its selected first

 
0
  #2
Mar 3rd, 2009
enable /disable the delete button in gridview based on the row selection.then this same code will works for u.let me know it works for u?
got solution ?, please mark the thread as Solved. Thanks & Regards,
srikanth kadem
srikanthkadem@rediffmail.com
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 41
Reputation: julseypart is an unknown quantity at this point 
Solved Threads: 0
julseypart julseypart is offline Offline
Light Poster

Re: prevent a file from being deleted unless its selected first

 
0
  #3
Mar 3rd, 2009
good idea!, does anyone have some sample code to allow only the delete button on the 'selected row' visible?
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: prevent a file from being deleted unless its selected first

 
0
  #4
Mar 10th, 2009
hi,

u can create delete button with in gridview itslef.check this example

  1. <asp:GridView ID="gdview" runat="server" ShowFooter="true" AutoGenerateColumns="False" DataKeyNames="CategoryID" OnRowCancelingEdit="gdview_RowCancelingEdit" OnRowDeleting="gdview_RowDeleting" OnRowEditing="gdview_RowEditing" OnRowUpdating="gdview_RowUpdating" Width="100%" AllowPaging="True" PageSize="5" OnPageIndexChanging="gdview_PageIndexChanging" OnRowDataBound="gdview_RowDataBound" >
  2. <Columns>
  3. <asp:BoundField HeaderText="Category Name" DataField="CategoryName" SortExpression="CategoryName" >
  4. <ItemStyle Height="20px" Width="150px" />
  5. </asp:BoundField>
  6.  
  7. <asp:CommandField ShowEditButton="True">
  8. <ItemStyle Width="100px" />
  9. </asp:CommandField>
  10. <asp:TemplateField>
  11.  
  12.  
  13.  
  14. <ItemTemplate>
  15. <asp:LinkButton ID="lnkdel" runat="server" Text="Delete" CommandName="Delete"></asp:LinkButton>
  16.  
  17. </ItemTemplate>
  18. <ItemStyle Width="100px" />
  19.  
  20. </asp:TemplateField>
  21. </Columns>
  22.  
  23.  
  24. </asp:GridView>
  25. protected void Page_Load(object sender, EventArgs e)
  26. {
  27.  
  28. if (!Page.IsPostBack)
  29. {
  30. bindgrid();
  31. total = 0;
  32.  
  33. }
  34.  
  35. }
  36.  
  37. public void bindgrid()
  38. {
  39. SqlConnection conn = new SqlConnection("Data Source='localhost';Initial Catalog='Northwind';Integrated Security=SSPI;Persist Security Info=False ");
  40. SqlCommand cmd = new SqlCommand("select CategoryName,CategoryID from Categories ", conn);
  41.  
  42. SqlDataAdapter da = new SqlDataAdapter("", conn);
  43. da.SelectCommand = new SqlCommand("select CategoryName,CategoryID from Categories", conn);
  44. DataSet ds = new DataSet();
  45. da.Fill(ds, "data");
  46. gdview.DataSource = ds.Tables[0].DefaultView;
  47. gdview.DataBind();
  48.  
  49.  
  50. }
  51. protected void gdview_RowDeleting(object sender, GridViewDeleteEventArgs e)
  52. {
  53.  
  54. int catid = int.Parse(gdview.DataKeys[0].Value.ToString());
  55. SqlConnection conn = new SqlConnection("Data Source='localhost';Initial Catalog='Northwind';Integrated Security=SSPI;Persist Security Info=False ");
  56. SqlDataAdapter da = new SqlDataAdapter("", conn);
  57. conn.Open();
  58. da.DeleteCommand = new SqlCommand("delete from Categories where CategoryID="+catid, conn);
  59. da.DeleteCommand.ExecuteNonQuery();
  60. conn.Close();
  61. bindgrid();
  62. }
If u r query is achieved,mark the thread as solved

Live and Let Live
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC