Re: delete confirmation in datagrid

Discussion in 'ASP .Net' started by sramruttun, Jul 4, 2003.

  1. sramruttun

    sramruttun Guest

    thanks Vidar - I'll try it and give u a feedback.

    "Vidar Petursson" <> wrote in message
    news:#...
    > Hi
    >
    > Make a function on the client that checks if any checkbox is checked...
    >
    > Basic example ( Should work in most browsers )
    > <html>
    > <head>
    > <script language="JavaScript">
    > function checkIt(f){
    > var e = f.elements;
    > var l = ( typeof(e.length) == "undefined") ? 0 : e.length;
    > var iCount = 0;
    > for(i=0;i<l;i++)
    > {
    > if(e.type == "checkbox") if(e.checked) iCount++;
    > }
    > if(iCount == 0 )
    > {
    > alert("Please select items to delete!");
    > return false;
    > }
    > else return confirm("Delete selectet item(s)?");
    > }
    > </script>
    > </head>
    > <body>
    > <form name="myForm">
    > <input type="checkbox" name="myCheckBox">
    > <input type="submit" onclick="return checkIt(this.form)" value="Check if
    > checkbox checked">
    > </form>
    > </body>
    > </html>
    >
    > Hope this helps!!
    >
    > --
    > Best Regards
    > Vidar Petursson
    > ==============================
    > Microsoft Internet Client & Controls MVP
    > ==============================
    > "sramruttun" <> wrote in message
    > news:%235w$...
    > > 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?
    > >
    > >

    >
    >
     
    sramruttun, Jul 4, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nedu N
    Replies:
    2
    Views:
    392
    Robert McLaws
    Dec 4, 2003
  2. JenHu
    Replies:
    6
    Views:
    5,260
    =?Utf-8?B?UGF1bCBK?=
    Feb 3, 2005
  3. DrData
    Replies:
    4
    Views:
    6,727
    Patrick Olurotimi Ige
    Mar 22, 2005
  4. Elton W
    Replies:
    0
    Views:
    3,320
    Elton W
    May 15, 2005
  5. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    Client Side Confirmation on DataGrid "Delete" LinkButton

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, May 2, 2006, in forum: ASP .Net
    Replies:
    8
    Views:
    9,724
    AcesHidden
    Nov 23, 2010
Loading...

Share This Page