Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Multiple Deletes in Gridview

Reply
Thread Tools

Multiple Deletes in Gridview

 
 
MasterChief
Guest
Posts: n/a
 
      02-07-2006
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.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      02-07-2006
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.
>
>

 
Reply With Quote
 
 
 
 
S. Justin Gengo [MCP]
Guest
Posts: n/a
 
      02-07-2006
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" <> wrote in message
news: 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.
>



 
Reply With Quote
 
George Ter-Saakov
Guest
Posts: n/a
 
      02-07-2006
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" <> wrote in message
news: 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.
>



 
Reply With Quote
 
MasterChief
Guest
Posts: n/a
 
      02-07-2006
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?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple file deletes using ftp.delete Drew Python 1 01-20-2007 07:58 AM
Alert to confirm deletes in the new GridView control dev648237923 ASP .Net Datagrid Control 1 11-20-2006 03:48 AM
Cache clearing deletes saved form info and history. Anyway not to have this happen? Jim Firefox 4 05-05-2005 06:15 AM
history.dat, formhistory.dat - deleting deletes history? S.Rodgers Firefox 4 05-05-2005 01:03 AM
Website deletes FireFox status bar Al. C Firefox 3 02-17-2005 06:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57