Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 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
  #1 (permalink)  
Old August 23rd, 2006, 02:12 PM
Registered User
Join Date: Aug 2006
Location: , , Canada.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default GridView and Row Index

How can I get the row index or even button index when I click on the button in a GridView row??

  #2 (permalink)  
Old October 16th, 2006, 04:18 PM
Wrox Author
Points: 165, Level: 3
Points: 165, Level: 3 Points: 165, Level: 3 Points: 165, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Oct 2006
Location: San Diego, CA, USA
Posts: 36
Thanks: 1
Thanked 5 Times in 5 Posts

                        <asp:GridView ID="gvCorrespondence" runat="server" DataKeyNames="[MY ID(s)]" AutoGenerateColumns="false">
                                    <td width="11%" class="topnavAddressBorder">
                                        <asp:ImageButton ID="ibtnAdd" runat="server" CommandName="Add" ImageUrl="~\images\btnAdd.gif"/>
                                        <asp:ImageButton ID="ibtnEdit" runat="server" CommandName="Edit" CommandArgument='<%#DataBinder.Eval(Container.Data Item, "[MY ID(s)]") %>' ImageUrl="~\images\btnEdit.gif"/>

Then in the OnItemCommand sub:

    Protected Sub OnItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) Handles gvCorrespondence.RowCommand

        Dim id As Decimal = -1


            id = cDec((e.CommandArgument))

            Select Case e.CommandName

                Case "Add"

                    Response.Redirect([DETAILS PAGE] & "ID=-1")

                Case "Edit"

                    Response.Redirect([NAVIGATE_TO] & "ID=" & id.ToString())

            End Select

        Catch ex As Exception

            Throw ex

        End Try

    End Sub

Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView - Skipping a Row gothael ASP.NET 2.0 Basics 1 July 18th, 2008 10:02 AM
Gridview with only one row mallikalapati ASP.NET 2.0 Professional 5 March 5th, 2008 09:27 AM
How to pass gridview selected row msbsam ASP.NET 2.0 Basics 1 March 4th, 2008 09:17 AM
Gridview with only one row mallikalapati ASP.NET 2.0 Professional 0 February 25th, 2008 06:46 AM
Getting a GridView Row to highlight gcm_uk ASP.NET 2.0 Basics 0 May 1st, 2007 05:55 AM

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