CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2002
    Location
    Czech
    Posts
    251

    DataGrid and MessageBox

    Hi all,
    I have been working in the ASP.NET for 4 days and encountered a problem.
    I have the DataGrid with the Button Column DELETE:
    -asp:ButtonColumn Text="Del" CommandName="Delete"--/asp:ButtonColumn-

    If a user clicks on the Del than appropriate record will be deleted.

    Well, and I want to display the message box for confirmation before deleting (“Are you sure to delete this record?” etc.) with YES and NO buttons.
    How to do this? Help, please.

    Thanks in advance,
    David
    Last edited by David Bajgar; October 15th, 2002 at 04:04 AM.

  2. #2
    Join Date
    Mar 2002
    Location
    Alpharetta, GA
    Posts
    51

  3. #3
    Join Date
    Aug 2002
    Posts
    33
    I don't see any topic related to this question? Is anyone has any idea how to do this?

  4. #4
    Join Date
    Aug 2002
    Posts
    33
    I found the code to handle this. Just add this code to the button which you want to display message:

    btnDeleteUser.Attributes.Add ("onclick", "return confirm('Are you sure you want to delete this user?');")

  5. #5
    Join Date
    Feb 2001
    Location
    TN
    Posts
    290
    That's cool! Can I also have something different happen if the user CANCELs?

    You know; like checking for IDCANCEL returned from a dialog in a VC++ Windows app.

    Where can I learn more about this 'Attributes.Add' stuff?
    Last edited by RickCrone; November 6th, 2002 at 05:00 PM.

  6. #6
    Join Date
    Jan 2002
    Location
    Czech
    Posts
    251
    Hi all,
    Great Stevehoang!
    I spent some time how to bind the Attributes with the delete column in the grid. You can do that if you cast the delete column to the LinkButton class. So, my hint is here:
    Code:
    LinkButton btn;
    foreach(DataGridItem item in DataGrid1.Items)
    {
    btn = (LinkButton)item.Cells[1].Controls[0];
    	btn.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this user?')");
    }
    David

  7. #7
    Join Date
    Nov 2002
    Location
    Columbus, Ohio
    Posts
    117

    how does this work

    First, Thanks. This is exactly what im looking for. My question is how exactly is this working. The click event in the c# code that is associated with the button by default only executes when the confirm response is ok. Thats what i want but dont know why its working. I was hoping someone could help explain whats happening. It seems to me that the "onclick" should be a function in the web page not a fucntion in the server side code. Also how does the return confirm(...) make it work on the ok but not the cancel. Any help would be appriciated.

  8. #8
    Join Date
    Jun 2003
    Posts
    10

    Good eample for you!

    Visit me at
    http://www34.brinkster.com/zeeinfo

  9. #9
    Join Date
    Jun 2003
    Posts
    10
    hi,

    For showing a message box u should use javascript function confirm for showing a message.

    ex:

    each button control has a property called Attribute


    MyDeleteButton.Attributes("onclick") = "return confirm('Are you sure you _ wish to delete this record?');"


    use the following code for performing the task

    rgds
    syam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured