Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 24th, 2004, 05:48 AM
Registered User
 
Join Date: Dec 2004
Location: , , .
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
  #2 (permalink)  
Old February 1st, 2005, 03:37 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:48 AM.


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