Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Asp.Net: datagrid with buttoncolumn and confirm

Posted on 2004-10-28
Medium Priority
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" ...>
   <asp:ButtonColumn Text="Close" ButtonType="PushButton" HeaderText="Close"
   <asp:TemplateColumn HeaderText="myKey" HeaderStyle-HorizontalAlign="Center"
                        ItemStyle-Width="15%" ItemStyle-HorizontalAlign="Center">
          <asp:Label id="lblMyKey" Text='<%# DataBinder.Eval(Container.DataItem, "myKey") %>' runat="server" />
    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:
                   = "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!

Question by:HStrix
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 28

Accepted Solution

mmarinov earned 2000 total points
ID: 12432441
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 & "\'?');"


Author Comment

ID: 12432678
Thank you very much mmarinov,
it works perfectly!


LVL 28

Expert Comment

ID: 12432703

hope that can be in help


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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