473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Multiple Deletes in Gridview

I have a customer that likes the gridview but instead of using the
standard Delete command for each row he wants to be able to put a
checkbox next to the row so he can chose multiple records and then
chose a delete button up top. What is the best way to accomplish that.
I have made a template in the gridview and added a checkbox. Then I
made a command button and changed is CommandName to Delete but after
that I don't really know what to do next.

Feb 7 '06 #1
4 3778
You can achieve that by using a TemplateField with an ItemTemplate containing
a CheckBox server control to build the first column of the GridView as I did
in this demo:
http://www.webswapp.com/codesamples/...ows_selection/

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"MasterChief" wrote:
I have a customer that likes the gridview but instead of using the
standard Delete command for each row he wants to be able to put a
checkbox next to the row so he can chose multiple records and then
chose a delete button up top. What is the best way to accomplish that.
I have made a template in the gridview and added a checkbox. Then I
made a command button and changed is CommandName to Delete but after
that I don't really know what to do next.

Feb 7 '06 #2
MasterChief,

Inside of the delete handler loop through the rows of the grid and look for
each checkbox. Then if the box is checked run a delete command based on that
row's id. Make certain that you set the GridView's DataKeyNames property to
the primary key field of your database so you can retrieve the row's id:

<asp:GridView ID="GridView1" runat="server" DataKeyNames="pk_InventoryId">
Dim CheckBox As CheckBox
Dim KeyId As Int32

For Each GridViewRow As GridViewRow In GridView1.Rows
'---Look at each checkbox here
CheckBox = CType(GridViewRow.FindControl("MyCheckBox"), CheckBox)

If CheckBox.Selected
'---Get the database id
KeyId = CType(GridView1.DataKeys.Item(GridViewRow.RowIndex ).Value,
Int32)

'---Use the KeytId to delete from the database.
End If
Next

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"MasterChief" <co*******@mix-net.net> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have a customer that likes the gridview but instead of using the
standard Delete command for each row he wants to be able to put a
checkbox next to the row so he can chose multiple records and then
chose a delete button up top. What is the best way to accomplish that.
I have made a template in the gridview and added a checkbox. Then I
made a command button and changed is CommandName to Delete but after
that I don't really know what to do next.

Feb 7 '06 #3
Actually in cases like that the simplest way is to fall back to regular ASP
style.
Meaning just add checkbox (not a server control) to the column and give them
name like
"chkDelete" + RecordId ( concatenate with a recordId)

then in you handler for the button you can have following code

foreach( string sKey in Request.Form )
{
if( sKey.IndexOf("chkDelete") == 1 )
{
......
}
}
George.

"MasterChief" <co*******@mix-net.net> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have a customer that likes the gridview but instead of using the
standard Delete command for each row he wants to be able to put a
checkbox next to the row so he can chose multiple records and then
chose a delete button up top. What is the best way to accomplish that.
I have made a template in the gridview and added a checkbox. Then I
made a command button and changed is CommandName to Delete but after
that I don't really know what to do next.

Feb 7 '06 #4
I see how that works but my next question is about the delete code.
What is the best way to connect to the database and do a delete in the
code behind file?

Feb 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Terry | last post by:
Good morning! How do I determine which SELECT button was clicked in a GridView? The multiple SELECT buttons will be used for an application approval process. Thank you in advance for your...
1
by: Eric | last post by:
I have a GridView control that I want to sort on multiple columns when I click a particular column. For example, I display Last name + ", " + First name in the first column and display id in the...
0
by: joebob8000 | last post by:
This seems like a simple task, but my 6 year old roots in classic ASP must be causing me trouble with my current problem. I am looking to provide a search for users in which they can select...
1
by: sheenaa | last post by:
Hello friends, I m using ASP.NET with C# 2005 and SQL SERVER 2005 for the ASP.Net Website. I m using sqldatasource to connect and retrieve the data from database and then it displays the data...
1
by: feltra | last post by:
Hi, The following is from my friend who has only restricted net access from his office and hence cannot post.... ...
0
by: feltra | last post by:
Hi all, I am trying to export a GridView data to multiple file formats. The requirement is that when more than one file format is selected and the "Submit" button is clicked, the data from the...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
2
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like...
0
by: suganya | last post by:
Hi I have a GridView in my Page. I have to bind multiple tables into the GridView using SQLDataSource. For that I have given the coding as <asp:GridView ID="Search_GridView" runat="server"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.