![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
|
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? |
#2
| |||
| |||
|
|
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? |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |