Solved

Asp.Net: datagrid with buttoncolumn and confirm

Posted on 2004-10-28
1,413 Views
Last Modified: 2008-01-16
Hello experts,
in my Asp.Net (vb.net) web application
I'm using in one web page the following definitions and code:
---
<asp:datagrid id="dgTest" ...>
...
<Columns>
   <asp:ButtonColumn Text="Close" ButtonType="PushButton" HeaderText="Close"
           CommandName="btnClose"></asp:ButtonColumn>
   <asp:TemplateColumn HeaderText="myKey" HeaderStyle-HorizontalAlign="Center"
                        ItemStyle-Width="15%" ItemStyle-HorizontalAlign="Center">
       <ItemTemplate>
          <asp:Label id="lblMyKey" Text='<%# DataBinder.Eval(Container.DataItem, "myKey") %>' runat="server" />
       </ItemTemplate>
   </asp:TemplateColumn>
....
</Columns>
</asp:datagrid>
---
    Private Sub dgTest_ItemDataBound(ByVal sender As Object, _
              ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgTest.ItemDataBound
        Select Case e.Item.ItemType
            Case ListItemType.AlternatingItem, ListItemType.Item
                Dim itemCell0 As TableCell = e.Item.Cells(0)
                Dim strItemNr As String = CType(e.Item.FindControl("lblMyKey"), Label).Text
                Dim closeButton As ButtonColumn
                ' till here everything seems to be OK
                '
                'How-to code the following lines:
                'closeButton.Attributes("onclick")
                   = "javascript:return confirm('Are you sure you want to close item \'" & strItemNr & "\'?')"
        End Select
    End Sub
---
The code above is intended to ask a confirmation query for each datagrid item.
But I couldn't make it work.

If anyone knows a solution please supply appropriate [snippet] information.

   Thank you very much!

     HStrix
0
Question by:HStrix
    3 Comments
     
    LVL 28

    Accepted Solution

    by:
    Hi HStrix,
    try this
    Dim btn as Button = CType(e.Item.Cells(0).Controls(0),Button) 'check if this is the 0-bazed or 1-based control
    btn.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to close item \'" & strItemNr & "\'?');"


    Regards!
    B..M
    0
     

    Author Comment

    by:HStrix
    Thank you very much mmarinov,
    it works perfectly!

      Regards

        HStrix
    0
     
    LVL 28

    Expert Comment

    by:mmarinov
    HStrix,

    hope that can be in help

    B..M
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    This video discusses moving either the default database or any database to a new volume.

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now