| | |
prevent a file from being deleted unless its selected first
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 41
Reputation:
Solved Threads: 0
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...
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
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...
ASP.NET Syntax (Toggle Plain Text)
void DeleteRowButton_Click(Object sender, EventArgs e) { LinkButton btn = sender as LinkButton; GridViewRow row = btn.NamingContainer as GridViewRow; if (row == GridView1.SelectedRow) { GridView1.DeleteRow(GridView1.SelectedIndex); // delete file from server } else lblDeleteResult.Text = "Please select this file first, if you wish to delete it"; }
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.
•
•
Join Date: Mar 2008
Posts: 68
Reputation:
Solved Threads: 11
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
hi,
u can create delete button with in gridview itslef.check this example
u can create delete button with in gridview itslef.check this example
ASP.NET Syntax (Toggle Plain Text)
<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" > <Columns> <asp:BoundField HeaderText="Category Name" DataField="CategoryName" SortExpression="CategoryName" > <ItemStyle Height="20px" Width="150px" /> </asp:BoundField> <asp:CommandField ShowEditButton="True"> <ItemStyle Width="100px" /> </asp:CommandField> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="lnkdel" runat="server" Text="Delete" CommandName="Delete"></asp:LinkButton> </ItemTemplate> <ItemStyle Width="100px" /> </asp:TemplateField> </Columns> </asp:GridView> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { bindgrid(); total = 0; } } public void bindgrid() { SqlConnection conn = new SqlConnection("Data Source='localhost';Initial Catalog='Northwind';Integrated Security=SSPI;Persist Security Info=False "); SqlCommand cmd = new SqlCommand("select CategoryName,CategoryID from Categories ", conn); SqlDataAdapter da = new SqlDataAdapter("", conn); da.SelectCommand = new SqlCommand("select CategoryName,CategoryID from Categories", conn); DataSet ds = new DataSet(); da.Fill(ds, "data"); gdview.DataSource = ds.Tables[0].DefaultView; gdview.DataBind(); } protected void gdview_RowDeleting(object sender, GridViewDeleteEventArgs e) { int catid = int.Parse(gdview.DataKeys[0].Value.ToString()); SqlConnection conn = new SqlConnection("Data Source='localhost';Initial Catalog='Northwind';Integrated Security=SSPI;Persist Security Info=False "); SqlDataAdapter da = new SqlDataAdapter("", conn); conn.Open(); da.DeleteCommand = new SqlCommand("delete from Categories where CategoryID="+catid, conn); da.DeleteCommand.ExecuteNonQuery(); conn.Close(); bindgrid(); }
If u r query is achieved,mark the thread as solved
Live and Let Live
Live and Let Live
![]() |
Similar Threads
- Cannot remove Golden Palace casino!! (Viruses, Spyware and other Nasties)
- Please Help! i got rb4.tmp and many other rb.tmp files in my RecycleBin & cant del em (Viruses, Spyware and other Nasties)
- Here is the doc file for the assignment (C++)
- hotoffers nightmare (Viruses, Spyware and other Nasties)
- Hotoffers get me mad !! (Viruses, Spyware and other Nasties)
- padobot.v (Viruses, Spyware and other Nasties)
- Help Hijackthis (Viruses, Spyware and other Nasties)
- Deleting stupid porn hijack (Viruses, Spyware and other Nasties)
- CWShredder problems (Viruses, Spyware and other Nasties)
- Hijack Log (Viruses, Spyware and other Nasties)
Other Threads in the ASP.NET Forum
- Previous Thread: Read value from DB
- Next Thread: Asp .Net with xml
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 3.5 ajax appliances application asp asp.net beginner box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox child class compatible confirmationcodegeneration content contenttype control countryselector courier database datagrid datagridview datalist deployment development dgv dialog dropdownmenu dynamic dynamically edit embeddingactivexcontrol feedback fileuploader fill findcontrol flash flv form forms gridview gudi homeedition hosting iis image javascript jquery list maps menu mobile mssql nameisnotdeclared news novell opera order parent problem ratings redirect registration relationaldatabases reportemail search security select serializesmo.table sessionvariables silverlight smoobjects software sql ssl tracking treeview typeof validatedate validation vb.net vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming wizard xml xsl





