Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 26th, 2004, 08:21 AM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Template Column in DataGrid and Button

Dear All,
I have a Template Column in my DataGrid with a LinkButton in it. I would like to delete one row with a confirmation on delete.
I have declared a LinkButton in my datagrid and in DataGrid1_ItemCreated I am adding a Javascript confirm code to linkButton's attribute. It works fine and I get the Confirmation and when I press on OK in goes to btnlinkDelete_Click sub nicely,

Here is my problem, I want to find out which row has been click to delete and I am using the following code to find out the DataGridItem:

Public Sub btnlinkDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlinkDelete.Click
        Dim myBtnDelete As LinkButton = CType(DataGrid1.FindControl("btnlinkDelete"), LinkButton)
        If Not myBtnDelete Is Nothing Then
            Dim objDataGridItem As DataGridItem = CType(myBtnDelete.Parent.Parent, DataGridItem)
            Dim subcatid_value As Integer = DataGrid1.DataKeys.Item(objDataGridItem.ItemIndex)
        End If

    End Sub

The first line of this function always returns NOTHING,
and that's why i can not find the DataGridItem to be able to find the DataKey

Please help me, I need this very soon,

Thanks very much indeed in advance

Behnam
 
Old January 23rd, 2005, 12:43 AM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try adding something like this to you grid itemcreated event. You will have to locate the link button (delete button) in your grid and add add an attribute to it.

Public Sub dgTemp_ItemCreated(ByVal system As Object, ByVal e As DataGridItemEventArgs)
        Try
            Select Case e.Item.ItemType
                Case ListItemType.Item, ListItemType.AlternatingItem
                    Dim tblTableCell As TableCell
                    tblTableCell = e.Item.Cells(4)
                    Dim lnkDelete As LinkButton
                    lnkDelete = tblTableCell.Controls(0)
                    lnkDelete.Attributes.Add("onclick", "return confirm('Are you Sure you want to delete this row?');")
                Case Else
                    Return
            End Select
        Catch ex As Exception

        End Try


    End Sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
Template Column in datagrid prankur ASP.NET 1.0 and 1.1 Professional 1 January 7th, 2006 05:20 PM
Datagrid Radio button template column issue satyajitk ASP.NET 1.0 and 1.1 Professional 6 November 26th, 2005 01:48 AM
template column in datagrid p2pMember ASP.NET 1.0 and 1.1 Basics 1 November 18th, 2005 06:33 PM
Button in Datagrid Template Column thetway ASP.NET 1.0 and 1.1 Basics 1 October 11th, 2005 01:54 PM
Datagrid template column sonurijs ASP.NET 1.x and 2.0 Application Design 1 September 27th, 2005 12:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.