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 24th, 2004, 05:48 AM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Buttons in DataGrid Template Column

Hi All
When I put a button in template column in my datagrid,
I get NOTHING in the command when I what to have access on that button.

Here is my code:

<asp:TemplateColumn HeaderText="Move Row">
<ItemTemplate>
    <asp:button Runat=server text ="UP" ID="btnMoveUp" OnClick = "btnMoveUp_click" />
    <asp:button Runat=server text ="Down" ID="btnMoveDown"/>
    </ItemTemplate>
</asp:TemplateColumn>

Sub btnMoveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveUp.Click
    Dim myBtnMoveUp As Button = CType(DataGrid1.FindControl("btnMoveUp"), Button)

     If Not myBtnMoveUp Is Nothing Then
            Dim objDataGridItem As DataGridItem = CType(myBtnMoveUp.Parent.Parent, DataGridItem)
        End If
End Sub

It’s always return NOTHING in btmMoveUp_Click
I am binding the datagrid in page load when it’s not PostBack
I put Protected withevent in top of code behind

Please help

Behnam
 
Old February 1st, 2005, 03:37 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can't use the "WithEvents" and "Handles" keyword for controls that live inside a repeating control template (such as a datagrid, datalist or repeater) because there will be multiple instances of that control. Instead you need to use the repeating control's ItemCommand event handler and check the event arguments for the 'Command' property. For a button, you set the 'Command' argument to some string value to indicate the desired action ("moveup", "movedown"), then you can check for this value in the ItemCommand event handler.

-Peter





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
template column in datagrid p2pMember ASP.NET 1.0 and 1.1 Basics 1 November 18th, 2005 06:33 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.