delete row or delete all in Gridview?

Hi there,

I have a Gridview that bind the data from the .mdb  and I want to have 2 delete buttions, one is delete a row and the other one is delete all from the database.  How do I do it in code behind in c#?  thanks a lot

11/1/2007 3:11:55 AM 72751 articles. 3 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 39

row delete  (temp call rowDel)

all delete (temp call allDel) 

with rowDel: i think you should bound one column in gridview  (or datagrid)


and bout allDel: i think you should use a button distinct with gridview.

Becoz your required is not complex , when allDel be push you don't care anything (like paging, or selected record)

only delete all record

too many way for design it.

i hope has more better methods will be  put out.




11/1/2007 3:56:03 AM

Hi,Orchid22 :

According to your request, you are suggested to use the inherited Delete button of gridview to delete a row.

To delete all row retrieved from database, you can add a button outside of the gridview.In event handler of Click event of the button,

use OleDbCommand to delete datas in database, the delete command should have the same "WHERE" clause as the DataSource which is bound to gridview, like

protected void Button1_Click(object sender, EventArgs e)
        System.Data.OleDb.OleDbConnection cnn = new System.Data.OleDb.OleDbConnection(connectionString);
        System.Data.OleDb.OleDbCommand cmd= new System.Data.OleDb.OleDbCommand("delete from table where clause here",cnn);

You can change the code according to your database. 

Hope it helps.
If you have any doubts about the post, please feel free to post back.

Techie Zhang
Microsoft Online Community Support
11/2/2007 8:49:09 AM

Similar Artilces:

How to delete controls in GridView when the delete button in a row is clicked
Hi,   I am having issues with my gridview.....i added 2 dropdown and 2 compare validators....whenever i delete a row though......the dropdown and compare validators are becoming null........thus when i click a button, it is still validating.............anyway to delete this when i click the delete button or even handle?   Please help.  ...

Adding data to gridview from two textboxes and then deleting them by delete button in each gridview row.
Hi, my app has 2 textboxes if i enter data and click add button they shud be added to gridview with 2 columns ex: custid from txtbox1 ... and custname frm txtbox2 added to gridview   with columns custid and custname then    foreach row a delete button shud appear in gridview and on clicking it shud delete the row can any one send me code for dis   thanks in advance Hi, In your Button Click Event write this code. DataControlField dCusId; DataControlField dCustName; dCusId.HeaderText = textbox1.text; dCustName.HeaderText = textbox2.text Gridv...

Gridview Delete not Deleting
I am trying to use a command button to delete a row from a gridview. When I click the command button though, the page posts but my record is still there... no errors, just nothing seems to happen. Below is what I think is the relevant code, let me know if you need to see anything else.  I'm kinda new to working with gridview objects, it would be nice if I could see what SQL command is acctually ran... maybe there are other things I can check too, I'm just not sure how.   <asp:GridView ID="GridView1" runat="server" AllowSorting="True"&nbs...

Delete a Row From A GridView Control
Well it is not just an ordinary delete. I have a Gridview which I populated manually. Then I need to delete a row which will be selected using a checkbox inside the gridview. I cant seem to find the way to just remove the specific row. I have already taken the rowIndex, but Gridview doesnt seem to allow me to delete a row unless I remove from a dataset or so. Anyhelp would be appreciated. Thanks - Mike use the property "DataKeyName" of the GridView. get the index and delete/remove the perticular row which you got through datakeyname property. and again bind your GridView. Thanx, [K...

How to delete row from GridView control
Hello,  I am working on an ASP.NET 2.0 app, and I am trying to wire up a "Delete" button to a gridview control on a form. Here is the code for the ASP :  <asp:GridView ID="gvInConditions" runat="server" AutoGenerateColumns="true" OnRowDeleting="gvInConditions_RowDeleting" DataKeyNames="Condition_ID" >         <Columns>                <asp:CommandField ButtonType="Button" SelectText=&...

Error with Gridview when i delete the row that have only one row in gridview
 Dear all, i develop with 2005 and use gridview and set enable deleteing =true. I can delete record in gridview properly but when gridveiw has only one row and then i'm clike delete button , the error occurs :   Server Error in '/it' Application. Specified argument was out of the range of valid values.Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeExce...

deleting a gridview row > deleting a record by id?
I know this is supposed to be really simple but I'm stumped, despite all my reading: I've got a gridview full of 'Categories' pulled rom my SQL db; each row has a (hidden) 'category_id' column. My delete button should ensure that the appropriate record is marked for deletion by category_id. I understand that somehow the point of a datagrid is that it is bound to my datatable - but how do I leverage that so that deleting a grid row (which might be row index 1) finds and deletes the correct record (which might be category_id 3125)? (All I need to do is flag...

Delete (Hide) Row from Gridview without deleting from DataBase
I am populating some data in a GridView.I added a column with a checkbox.Now I want to generate a sort of print-preview...When Ich check some buttons and hit my printpriview button. I only want these (selected rows displayed).How can I do this?The checkbox thing is already working What I basically need is something to delete data temporaly from a GridView (not Database).I tryed GridViewRow.Dispose() which worked but then the paging was still implementet and the user sees still all pages =(I have tryed GridViewRow.Enabled = false which only turned the colors =(I have used GridViewRow.Visible ...

Deletes are not being deleted.
Using ASA 7.03 I am having a problem in deleting field service orders that have been completed. Just getting started with sync so I am probably making a dumb mistake or just leaving out a step. The download_delete_cursor script is: Select ordernumber from ServiceOrderEntryMaster where Tech = ? and Order_Complete = 'Y' This based on the verbose reply from the MobiLink Synchronization server is picking the correct work order ( number 326 ) and showing a Delete Row line in the log. But the work order is not being deleted on the remote side. What could I be doing wron...

Help on deleting a row in Gridview control
Hi, I need to find out how to delete a row in the GridView control.  I have the following delete control in my GridView:<CODE><asp:TemplateField ItemStyle-HorizontalAlign=center ItemStyle-VerticalAlign="top"><ItemTemplate><asp:ImageButton ID=ibDelete runat=server ImageUrl="~/Images/delete.gif" CommandName="Delete"/></ItemTemplate> </asp:TemplateField></CODE> What events do I use and how do I get them to fire?  I just started using Gridviews.thanks. Hey,That should all you need to delete a row; a cli...

Client-Side Delete from Gridview(Hide-row and delete when page is saved)
Is there any way to hide a row dynamically in a gridview without a postback?  Each row in my grid has a delete button.  When the delete button is pressed I want it to appear to the user as if the corresponding row has been deleted.   The delete won't actually take place until there is a postback.  I am using and javascript.  Here is a stripped down version of what I have.    <script type="text/javascript" > function getParentObjectId(fromId) { var str; var indx; indx = fromId.lastIndexOf("_"); str = fr...

Delete Control Button in Gridview Row at RowDataBound
I'd like to Delete a Control Button in a Gridview Row at RowDataBound, based on certain criteria.  I can locate the control during the event routine, but:Set = nothing gives "read only"Dispose =  has no effect Any suggestions on how I might be able to delete this button in this situation would be appreciated.Thanks!(PS:  one alt is to ADD the button in row created under the opposite criteria...I was hoping the get the above approach to work first, since it allows vanilla generation of the button.)  got RowDatabound....If e.Row.RowType = D...

Delete Row Method (getting the primarykey of row being deleted)
Hello friends,I'd like to retrieve the primary key of the row being deleted so i can use it as a parameter in my stored procedure: Here's how far i have come with my code. I need help with line 6.Thanks in advance :)  1 Protected Sub DependentsObjectDataSource_Deleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles DependentsObjectDataSource.Deleting2 3 'get value of deleting depednent id4 'Delete (Unenroll) all benefits dependent enrolled in before attempting to delete dependen...

When I delete something in my GridView, my data is delete in the database but not on my GridView
I've got a GridView, when I click on the delete button, my data is deleted in the database but not on my GridView. When I press on F5 for refresh my browser, my datarow is deleted. So is it possible the clear the cache of the GridView ? Or is there an other solution for this problem ? Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) rebind your gridview... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) darkcat02: rebind your gridview...  rebinding is the process u have to do if u re manually binding to the gridview. in case ...

Web resources about - delete row or delete all in Gridview? -

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012 - Upcoming stories is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 1/3/2016 2:58:45 AM