HighTechTalks DotNet Forums  

Re: delete confirmation in datagrid

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss Re: delete confirmation in datagrid in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Vidar Petursson
 
Posts: n/a

Default Re: delete confirmation in datagrid - 07-03-2003 , 04:26 PM






Hi

Answered in microsoft.public.dotnet.framework.aspnet

--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
"sramruttun" <sramruttun (AT) yahoo (DOT) com> wrote

Quote:
hi
I have a datagrid with 4 columns. 1st col shows the client code, 2nd col
shows the client name, 3rd col shows his address and the 4th is a template
col in which I have a delete button (in fact it is an imagebutton) in the
header section and checkboxes in the item section. The idea is to select 1
or more clients and then delete. Then I added a delete confirmation
message
to the button as follows:

In the ItemCreated event of the datagrid:
If e.Item.ItemType = ListItemType.Header Then
Dim DelButton As ImageButton = CType(e.Item.FindControl("ImgDel"),
ImageButton)
DelButton.Attributes.Add("onclick", "return confirm('Are you sure you
want
to delete the selected item(s)?');")
endif

In HTML Source of the .aspx:
asp:TemplateColumn> <HeaderTemplate
asp:ImageButton id="ImgDel" onClick="Delete_Items" runat="server"
CausesValidation="False" ImageUrl="Images/del.gif"
/asp:ImageButton> </HeaderTemplate


The sub Delete_Items:
Protected Sub Delete_Items(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs)
Dim oItem As DataGridItem
Dim sKeys As New ArrayList

For Each oItem In DataGrid1.Items
If CType(oItem.FindControl("chkDel"), CheckBox).Checked Then
sKeys.Add(DataGrid1.DataKeys(oItem.ItemIndex))
End If
Next

If sKeys.Count <> 0 Then
DeleteClient(sKeys) 'This sub does the actual deletion
End If
End Sub

This technique works. The problem is that if I click the Delete button
even
if I've not checked any of the checkboxes, it asks me for the delete
confirmation. Do u think there's a way to skip this if no items are
checked?





Reply With Quote
  #2  
Old   
sramruttun
 
Posts: n/a

Default Re: delete confirmation in datagrid - 07-07-2003 , 01:41 AM






thanks Vidar, it worked out.

"Vidar Petursson" <theking (AT) icysoft (DOT) com> wrote

Quote:
Hi

Answered in microsoft.public.dotnet.framework.aspnet

--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
"sramruttun" <sramruttun (AT) yahoo (DOT) com> wrote in message
news:%23llQafSQDHA.3192 (AT) tk2msftngp13 (DOT) phx.gbl...
hi
I have a datagrid with 4 columns. 1st col shows the client code, 2nd col
shows the client name, 3rd col shows his address and the 4th is a
template
col in which I have a delete button (in fact it is an imagebutton) in
the
header section and checkboxes in the item section. The idea is to select
1
or more clients and then delete. Then I added a delete confirmation
message
to the button as follows:

In the ItemCreated event of the datagrid:
If e.Item.ItemType = ListItemType.Header Then
Dim DelButton As ImageButton = CType(e.Item.FindControl("ImgDel"),
ImageButton)
DelButton.Attributes.Add("onclick", "return confirm('Are you sure you
want
to delete the selected item(s)?');")
endif

In HTML Source of the .aspx:
asp:TemplateColumn> <HeaderTemplate
asp:ImageButton id="ImgDel" onClick="Delete_Items" runat="server"
CausesValidation="False" ImageUrl="Images/del.gif"
/asp:ImageButton> </HeaderTemplate


The sub Delete_Items:
Protected Sub Delete_Items(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs)
Dim oItem As DataGridItem
Dim sKeys As New ArrayList

For Each oItem In DataGrid1.Items
If CType(oItem.FindControl("chkDel"), CheckBox).Checked Then
sKeys.Add(DataGrid1.DataKeys(oItem.ItemIndex))
End If
Next

If sKeys.Count <> 0 Then
DeleteClient(sKeys) 'This sub does the actual deletion
End If
End Sub

This technique works. The problem is that if I click the Delete button
even
if I've not checked any of the checkboxes, it asks me for the delete
confirmation. Do u think there's a way to skip this if no items are
checked?







Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.