Subject: a problem of adding a confirm window to delete but
Posted By: raybristol Post Date: 12/8/2005 7:30:20 PM
hi i have a template column in datagrid, i have a button in header template, checkbox for itemtemplate, so i can delete multiple rows, my code works fine for that but I need to tell user what items will be deleted before they press 'OK' button in the popup windows, i have a problem of collecting selected item's ID, in my code, the selected item's ID only will be collected after user press 'OK' button in the popup window. my code for aspx page is in below:

<asp:TemplateColumn HeaderText="Delete" HeaderStyle-Width=70px>
<HeaderTemplate>
'DeleteStore will look for checked item and perform delete
<asp:button id=delConfirm onclick=DeleteStore runat="server" Width="62px" Text="Reject" Font-Bold=True ></asp:button>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox id=DeleteThis Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>


in DeleteStore I use following code to search all the checked checkbox:

   For Each i As DataGridItem In DataGrid1.Items
      Dim deleteChkBxItem As CheckBox = CType(i.FindControl("DeleteThis"), CheckBox)
'delIDs will be assigned selected item's ID
                      If deleteChkBxItem.Checked Then
                          delIDs += CType(i.FindControl("Hyperlink8"), HyperLink).Text.ToString + ","
'Label5.Text is for debugging purpose
                          Label5.Text = delIDs
                      End If
Next

however, I want to put all the selected item information in the popup confirm window, which will be the value of delIDs, however if I put above code combine with the popup confirm window code like this:

Private Sub DataGrid1_ItemGreated(ByVal Sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemCreated
      Select Case e.Item.ItemType
          Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem, ListItemType.Header
              Dim myDeleteButton As WebControl
              myDeleteButton = e.Item.FindControl("delConfirm")

              If myDeleteButton Is Nothing Then
              Else
         
   'I dun know why this for loop is run after "return confirm...

                  For Each i As DataGridItem In DataGrid1.Items
                      Dim deleteChkBxItem As CheckBox = CType(i.FindControl("DeleteThis"), CheckBox)

                      If deleteChkBxItem.Checked Then
                          delIDs += CType(i.FindControl("Hyperlink8"), HyperLink).Text.ToString + ","
                          Label5.Text = delIDs
                      End If
                  Next



                  myDeleteButton.Attributes.Add("onclick", "return confirm('Are you sure you want to delete the following News? " + delIDs + " ');")

              End If
      End Select
      chkState()
  End Sub


in above code, statement "  myDeleteButton.Attributes.Add("onclick", "return confirm('Are you sure you want to delete the following News? " + delIDs + " ');")" is for adding the confirm window before delete action, it suppose to display all the selected item's ID (delIDs) in the popup window, however, delIDs is not assigned with selected items' ID until I press ok in the confirm window (I can see this by viewing Lable5's text, because I also assign Lable5's text = delIDs)     

I hope this is clear, thanks so much for your help!

*sorry i posted this one on ADO.net, but i just notice there is a ASP.NET!*

Reply By: planoie Reply Date: 12/12/2005 4:01:54 PM
Cross post: http://p2p.wrox.com/topic.asp?TOPIC_ID=37410

Go to topic 37533

Return to index page 418
Return to index page 417
Return to index page 416
Return to index page 415
Return to index page 414
Return to index page 413
Return to index page 412
Return to index page 411
Return to index page 410
Return to index page 409