Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional 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 July 9th, 2008, 11:45 PM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default Can't find control in GridView RowCommand

I have spent the last several hours researching this and I am certain I am doing this exactly like others (most of the examples are in C# and I'm using VB). I Am simply trying to get access to a label in my GridView's row. Below is my GridView and then is my code behind. What I don't understand is when I put a break point in the RowCommand and try placing watches, I get the following:

e.commandargument = ""
e.commandarguement.tostring = run time error - trying to cast "" to Integer
GridView1.selectedIndex = -1 (?? Have NO idea why -1 - shouldn't be the row?)
gridview1.DataKeys.Item(0) = gets me the GUID in the DataKeyNames - but I don't know how to get a reference to the row

I have tried all sorts of ways to get a reference to the selected row--but e.commandargument is not working.....


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        DataSourceID="ObjectDataSource1" GridLines="None" Font-Size="Small" DataKeyNames="UserID">
        <Columns>
            <asp:TemplateField HeaderText="Name">

                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# ReturnName(Eval("MemberID")) %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle Font-Underline="True" ForeColor="#6600CC" />
                <ItemStyle CssClass="col" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Work Location">
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# ReturnLocation(Eval("workLocationID")) %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle Font-Underline="True" ForeColor="#6600CC" />
                <ItemStyle CssClass="col" />
            </asp:TemplateField>
            <asp:BoundField DataField="phone" HeaderText="Work Phone">
                <HeaderStyle Font-Underline="True" ForeColor="#6600CC" />
                <ItemStyle CssClass="col" />
            </asp:BoundField>
            <asp:BoundField DataField="mobPhone" HeaderText="Cell Phone">
                <HeaderStyle Font-Underline="True" ForeColor="#6600CC" />
                <ItemStyle CssClass="col" />
            </asp:BoundField>
            <asp:TemplateField HeaderText="Committee">
                <ItemTemplate>
                    <asp:Label ID="Label3" Text='<%# ReturnCommittee(Eval("positionID")) %>' runat="server"></asp:Label>
                </ItemTemplate>
                <HeaderStyle Font-Underline="True" ForeColor="#6600CC" />
                <ItemStyle CssClass="col" />
            </asp:TemplateField>
            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="ActivateButton" runat="server" CausesValidation="false"
                        CommandName="activate" text='button'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>

    </asp:GridView>



Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) Handles GridView1.RowCommand
        If e.CommandName.ToLower = "activate" Then

            Dim myLabel As Label
            Dim iRowIndex As Integer
            Integer.TryParse(e.CommandArgument.ToString, iRowIndex)

            myLabel = CType(GridView1.Rows(iRowIndex).FindControl("Label 1"), Label)

        End If
    End Sub




  #2 (permalink)  
Old July 10th, 2008, 02:33 AM
Imar's Avatar
Wrox Author
Points: 72,035, Level: 100
Points: 72,035, Level: 100 Points: 72,035, Level: 100 Points: 72,035, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,079
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Rob,

If this is related to your previous message, there's a fair chance you are overwriting the data before this handler is hit. That way, you rebind the GridView and thus wipe out the selected index.

Again, the best way to find these kind of issues out is to comment a lot of other code. Get rid of the SelectedIndexChanged, get rid of RefreshCalendar and so on. Or better, create a simple demo page.

The code you have should work in theory; you probably just wipe out your own selection before you can access it....

http://msdn.microsoft.com/en-us/libr...nthandler.aspx

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old July 10th, 2008, 07:44 AM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Imar,

Thanks for your help. Same app - but page doesn't have a single calander on it : )
Also - I had come across the link you gave - like I said - everything I've looked at should mean I can do this. When I ran below code, put breakpoint and put "Convert.ToInt32(e.commandargument)" in watch, I get runtime error because it's returning ""


Actually - here's the entire page (you can pretty much guess the data layers and business layers - modeled after your app - but I'll include them below)

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="activatemembers.aspx.vb" Inherits="Admin_activatemembers" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        DataSourceID="ObjectDataSource1" GridLines="None" Font-Size="Small" DataKeyNames="UserID">
        <Columns>
            <asp:TemplateField HeaderText="Name">

                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# ReturnName(Eval("MemberID")) %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle Font-Underline="True" ForeColor="#6600CC" />
                <ItemStyle CssClass="col" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Work Location">
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# ReturnLocation(Eval("workLocationID")) %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle Font-Underline="True" ForeColor="#6600CC" />
                <ItemStyle CssClass="col" />
            </asp:TemplateField>
            <asp:BoundField DataField="phone" HeaderText="Work Phone">
                <HeaderStyle Font-Underline="True" ForeColor="#6600CC" />
                <ItemStyle CssClass="col" />
            </asp:BoundField>
            <asp:BoundField DataField="mobPhone" HeaderText="Cell Phone">
                <HeaderStyle Font-Underline="True" ForeColor="#6600CC" />
                <ItemStyle CssClass="col" />
            </asp:BoundField>
            <asp:TemplateField HeaderText="Committee">
                <ItemTemplate>
                    <asp:Label ID="Label3" Text='<%# ReturnCommittee(Eval("positionID")) %>' runat="server"></asp:Label>
                </ItemTemplate>
                <HeaderStyle Font-Underline="True" ForeColor="#6600CC" />
                <ItemStyle CssClass="col" />
            </asp:TemplateField>
            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="ActivateButton" runat="server" CausesValidation="false"
                        CommandName="activate" text='button'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>

    </asp:GridView>

    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
        SelectMethod="GetList" TypeName="Searing.Sprint.CusotmerAdvocacy.Dal.Memb erDB"></asp:ObjectDataSource>
</asp:Content>



ACTIVATEMEMBERS.ASPX.VB
Imports Searing.Sprint.CustomerAdvocacy.Bll
Imports Searing.Sprint.CusotmerAdvocacy.Dal
Imports Searing.Sprint.CustomerAdvocacy.BO

Partial Class Admin_activatemembers
    Inherits System.Web.UI.Page



    Public Function ReturnName(ByVal memberID As Integer) As String
        Dim fullName As String
        Dim myMember As New Member
        myMember = MemberManager.GetItem(memberID)
        fullName = myMember.FName + " " + myMember.LName
        Return fullName
    End Function

    Public Function ReturnLocation(ByVal wlocationID As Integer) As String
        Dim myWorkLocation As New WorkLocation
        myWorkLocation = WorkLocationManager.GetItem(wlocationID)
        Return myWorkLocation.LocationName
    End Function

    Public Function ReturnCommittee(ByVal positionID As Integer) As String
        Dim myPosition As New Position
        myPosition = PositionManager.GetItem(positionID)
        Return myPosition.PositionName
    End Function

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) Handles GridView1.RowCommand
        If e.CommandName.ToLower = "activate" Then

            Dim myLabel As Label
            Dim iRowIndex As Integer
            Integer.TryParse(e.CommandArgument.ToString, iRowIndex)

            myLabel = CType(GridView1.Rows(iRowIndex).FindControl("Label 1"), Label)

        End If
    End Sub
End Class


MemberManager.VB

Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient
Imports System.ComponentModel
Imports Searing.Sprint.CustomerAdvocacy.BO
Imports Searing.Sprint.CusotmerAdvocacy.Dal

Namespace Searing.Sprint.CustomerAdvocacy.Bll
    Public Class MemberManager

        Public Shared Function Save(ByVal myMember As Member) As Integer
            Return MemberDB.Save(myMember)
        End Function

        Public Shared Function GetItem(ByVal myMemberID As Integer) As Member
            Return MemberDB.GetItem(myMemberID)
        End Function

        Public Shared Function GetList() As MemberList
            Return MemberDB.GetList()
        End Function

        Public Shared Sub SaveMemberEvent(ByVal memberID As Integer, ByVal eventID As Integer)
            MemberDB.SaveMemberEvent(memberID, eventID)
        End Sub

        Public Shared Function GetMemberWithGuid(ByVal myGuid As Guid) As Member
            Return MemberDB.GetMemberWithGuid(myGuid)
        End Function

        Public Shared Function GetMembersInEventByDate(ByVal myDate As Date) As MemberList
            Return MemberDB.GetMembersEnrolledInEventByDate(myDate)
        End Function


    End Class
End Namespace


MemberDB.vd

Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient
Imports Searing.Sprint.CustomerAdvocacy.BO

Namespace Searing.Sprint.CusotmerAdvocacy.Dal

    Public Class MemberDB

        Public Shared Function GetMembersWithInterest(ByVal interestID As Integer) As MemberList
            Dim tempList As MemberList = Nothing
            ' Using
            Dim myConnection As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString)
            Try
                Dim myCommand As SqlCommand = New SqlCommand("sprocMemberSelectMembersWithInterest", myConnection)
                myCommand.CommandType = CommandType.StoredProcedure
                myCommand.Parameters.AddWithValue("@interestID", interestID)
                myConnection.Open()
                ' Using
                Dim myReader As SqlDataReader = myCommand.ExecuteReader
                Try
                    If myReader.HasRows Then
                        tempList = New MemberList
                        While myReader.Read
                            tempList.Add(FillDataRecord(myReader))
                        End While
                    End If
                    myReader.Close()
                Finally
                    CType(myReader, IDisposable).Dispose()
                End Try
            Finally
                CType(myConnection, IDisposable).Dispose()
            End Try
            Return tempList
        End Function

        Public Shared Function GetMembersEnrolledInEventByDate(ByVal myDate As Date) As MemberList
            Dim tempList As MemberList = Nothing
            ' Using
            Dim myConnection As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString)
            Try
                Dim myCommand As SqlCommand = New SqlCommand("sprocMemberSelectListByEventDate", myConnection)
                myCommand.CommandType = CommandType.StoredProcedure
                myCommand.Parameters.AddWithValue("@myDate", myDate)
                myConnection.Open()
                ' Using
                Dim myReader As SqlDataReader = myCommand.ExecuteReader
                Try
                    If myReader.HasRows Then
                        tempList = New MemberList
                        While myReader.Read
                            tempList.Add(FillDataRecord(myReader))
                        End While
                    End If
                    myReader.Close()
                Finally
                    CType(myReader, IDisposable).Dispose()
                End Try
            Finally
                CType(myConnection, IDisposable).Dispose()
            End Try
            Return tempList
        End Function

        Public Shared Function GetItem(ByVal memberID As Integer) As Member
            Dim myMember As Member = Nothing
            ' Using
            Dim myConnection As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString)
            Try
                Dim myCommand As SqlCommand = New SqlCommand("sprocMemberSelectSingleItem", myConnection)
                myCommand.CommandType = CommandType.StoredProcedure
                myCommand.Parameters.AddWithValue("@memberID", memberID)
                myConnection.Open()
                ' Using
                Dim myReader As SqlDataReader = myCommand.ExecuteReader
                Try
                    If myReader.Read Then
                        myMember = FillDataRecord(myReader)
                    End If
                    myReader.Close()
                Finally
                    CType(myReader, IDisposable).Dispose()
                End Try
                myConnection.Close()
            Finally
                CType(myConnection, IDisposable).Dispose()
            End Try
            Return myMember
        End Function


        Public Shared Function GetList() As MemberList
            Dim tempList As MemberList = Nothing
            ' Using
            Dim myConnection As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString)
            Try
                Dim myCommand As SqlCommand = New SqlCommand("sprocMemberSelectList", myConnection)
                myCommand.CommandType = CommandType.StoredProcedure
                myConnection.Open()
                ' Using
                Dim myReader As SqlDataReader = myCommand.ExecuteReader
                Try
                    If myReader.HasRows Then
                        tempList = New MemberList
                        While myReader.Read
                            tempList.Add(FillDataRecord(myReader))
                        End While
                    End If
                    myReader.Close()
                Finally
                    CType(myReader, IDisposable).Dispose()
                End Try
            Finally
                CType(myConnection, IDisposable).Dispose()
            End Try
            Return tempList
        End Function

        Public Shared Function GetMemberWithGuid(ByVal myGuid As Guid) As Member
            Dim myMember As Member = Nothing
            ' Using
            Dim myConnection As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString)
            Try
                Dim myCommand As SqlCommand = New SqlCommand("sprocGetMemberWithUserID", myConnection)
                myCommand.CommandType = CommandType.StoredProcedure
                myCommand.Parameters.AddWithValue("@userID", myGuid)
                myConnection.Open()
                ' Using
                Dim myReader As SqlDataReader = myCommand.ExecuteReader
                Try
                    If myReader.Read Then
                        myMember = FillDataRecord(myReader)
                    End If
                    myReader.Close()
                Finally
                    CType(myReader, IDisposable).Dispose()
                End Try
                myConnection.Close()
            Finally
                CType(myConnection, IDisposable).Dispose()
            End Try
            Return myMember
        End Function

        Private Shared Function FillDataRecord(ByVal myDataRecord As IDataRecord) As Member
            Dim myMember As Member = New Member
            myMember.MemberID = myDataRecord.GetInt32(myDataRecord.GetOrdinal("mem berID"))
            myMember.UserID = myDataRecord.GetGuid(myDataRecord.GetOrdinal("user ID"))
            myMember.FName = myDataRecord.GetString(myDataRecord.GetOrdinal("fN ame"))
            myMember.LName = myDataRecord.GetString(myDataRecord.GetOrdinal("lN ame"))
            myMember.Phone = myDataRecord.GetString(myDataRecord.GetOrdinal("ph one"))
            myMember.MobPhone = myDataRecord.GetString(myDataRecord.GetOrdinal("mo bPhone"))
            myMember.WorkLocationID = myDataRecord.GetInt32(myDataRecord.GetOrdinal("wor kLocationID"))
            myMember.PositionID = myDataRecord.GetInt32(myDataRecord.GetOrdinal("pos itionID"))
            Return myMember
        End Function

        Public Shared Function SaveMemberEvent(ByVal memberID As Integer, ByVal eventID As Integer) As Integer
            Dim result As Integer = 0
            Dim myConnection As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString)
            Try
                Dim myCommand As SqlCommand = New SqlCommand("sprocMemberEnrollEvent", myConnection)
                myCommand.CommandType = CommandType.StoredProcedure
                myCommand.Parameters.AddWithValue("@memberID", memberID)
                myCommand.Parameters.AddWithValue("@eventID", eventID)
                Dim returnValue As DbParameter
                returnValue = myCommand.CreateParameter
                returnValue.Direction = ParameterDirection.ReturnValue
                myCommand.Parameters.Add(returnValue)
                myConnection.Open()
                myCommand.ExecuteNonQuery()
                result = Convert.ToInt32(returnValue.Value)
                myConnection.Close()
            Finally
                CType(myConnection, IDisposable).Dispose()
            End Try
        End Function

        Public Shared Function Save(ByVal myMember As Member) As Integer
            Dim result As Integer = 0
            Dim result2 As Integer = 0
            ' Using
            Dim myConnection As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString)
            Try
                Dim myCommand As SqlCommand = New SqlCommand("sprocMemberInsertUpdateSingleItem", myConnection)
                myCommand.CommandType = CommandType.StoredProcedure
                If myMember.MemberID = -1 Then
                    myCommand.Parameters.AddWithValue("@memberID", DBNull.Value)
                Else
                    myCommand.Parameters.AddWithValue("@memberID", myMember.MemberID)
                End If
                myCommand.Parameters.AddWithValue("@userID", myMember.UserID)
                myCommand.Parameters.AddWithValue("@fName", myMember.FName)
                myCommand.Parameters.AddWithValue("@lName", myMember.LName)
                myCommand.Parameters.AddWithValue("@phone", myMember.Phone)
                myCommand.Parameters.AddWithValue("@mobPhone", myMember.MobPhone)
                myCommand.Parameters.AddWithValue("@workLocationID ", myMember.WorkLocationID)
                myCommand.Parameters.AddWithValue("@positionID", myMember.PositionID)

                Dim returnValue As DbParameter
                returnValue = myCommand.CreateParameter
                returnValue.Direction = ParameterDirection.ReturnValue
                myCommand.Parameters.Add(returnValue)
                myConnection.Open()
                myCommand.ExecuteNonQuery()
                result = Convert.ToInt32(returnValue.Value)
                myConnection.Close()
            Finally
                CType(myConnection, IDisposable).Dispose()
            End Try

            For Each myInterest As Interest In myMember.Interests
                Dim myConnection2 As SqlConnection = New SqlConnection(AppConfiguration.ConnectionString)
                Try
                    Dim myCommand As SqlCommand = New SqlCommand("sprocMemberInterestInsertUpdateSingleI tem", myConnection2)
                    myCommand.CommandType = CommandType.StoredProcedure

                    myCommand.Parameters.AddWithValue("@memberID", result)
                    myCommand.Parameters.AddWithValue("@interestID", myInterest.InterestID)

                    Dim returnValue As DbParameter
                    returnValue = myCommand.CreateParameter
                    returnValue.Direction = ParameterDirection.ReturnValue
                    myCommand.Parameters.Add(returnValue)
                    myConnection2.Open()
                    myCommand.ExecuteNonQuery()
                    result2 = Convert.ToInt32(returnValue.Value)
                    myConnection.Close()
                Finally
                    CType(myConnection, IDisposable).Dispose()
                End Try

            Next

            Return result2
        End Function


    End Class

End Namespace





  #4 (permalink)  
Old July 10th, 2008, 02:06 PM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

OK--I think I figured it out . If you look at what is causing the command - it's actually a "linkButton" inside an itemTemplate. When I deleted this and simply put a "buttonfield" it started working.

Something about the linkbutton in the template not firing a select or something - which is odd - because I put a debug in the rowcommand - and clicking the linkbutton was triggering a rowcommand call - but just different behavior than getting there via the buttonfield.

(just added)

NOW I know why I did that...I did add a buttonField--but then converted to a template - so that I could gain access to the linkbutton's ID because I wanted to dynamically change the "name" of the button. Basically, I want it to say either "activate" or "deactivate" - then based upon the text I would do one of two things.....

SO just odd that it works when it's a buttonfield - but not when you convert to template-----is there a way to grab the id of the buttonlink?

-Rob
  #5 (permalink)  
Old July 10th, 2008, 11:28 PM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

I think I might be on to something, but not sure if this is the issue-and if so - this is C#, not really understanding what it is doing - so if it is correct, would love the VB equivalent.

Basically, I am trying to get a reference to a buttonfield in my gridview. I thus, converted it to a template. Upon the rowcommand method, e.commandarguments returns nothing (as I am trying to get the row index to work some sort of find control). Here's what someone suggested - not sure what it's doing (found at http://www.c-sharpcorner.com/Forums/...ThreadID=38974)

protected void mygridView_RowDataBound(object sender, GridViewRowEventsArgs e) {

        if (e.Row.RowType == DataControlRowType.DataRow) {

              //Button linkbutton = e.Row.Cells[0].FindControls("lnkButton") as LinkButton;

             linkbutton .CommandArgument = e.Row.RowIndex.ToString()

      }

}

after that in the RowCommand event of the gridview

protected void mygridView_RowCommand(object sender,
GridViewCommandEventArgs e)
{

int RowIndex_ = int.Parse(e.CommandArgument.ToString());
TextBox txtBox =
(TextBox )mygridView.Rows[RowIndex].FindControl("textBoxID");

}


  #6 (permalink)  
Old July 11th, 2008, 08:18 PM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

OK - I FIGURED IT OUT!!!..err..rather, I figured out a way to solve my problem, however I am still unclear as to why, when you add a buttonfield, and convert it to a template, when you add a breakpoint to the rowcommand method (which does activate) then "e.commandarguments" is always nothing - so you cannot tie to the specific row that was picked and thus get a reference to the button.

Rather - I found a solution where you tie into the rowdatabound method and add your own handler to linkbutton - you can actually reference it via the way I do below. So - I scratched using the rowcommand and used rowdatabound with my own method. I will remove the implementation of it - and show you the skeleton to how I solved this:

First, set your control up, in your GridView, so that:

<asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="myButton" onclick="LinkButton_Click" runat="server" Text="Button" />
                </ItemTemplate>
            </asp:TemplateField>

Then here is the RowDataBound method:

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim myLinkButton As LinkButton
            myLinkButton = CType(e.Row.Cells(5).FindControl("myButton"), LinkButton)
            myLinkButton.Text = "ROCKON"
            AddHandler myLinkButton.Click, AddressOf LinkButton_Click

        End If

    End Sub


Finally, the signature of your custom eventhandler:

 Protected Sub LinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)


    End Sub

Hope this eventually saves someone the amount of research I've done over the past several days.



  #7 (permalink)  
Old July 14th, 2008, 01:06 AM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Very much appreciated. Thank you for posting your solution.

Richard

  #8 (permalink)  
Old October 16th, 2008, 07:19 PM
Registered User
 
Join Date: Oct 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks so much for posting this solution.
Came across the same problem and was trying everything.

  #9 (permalink)  
Old September 10th, 2011, 07:10 PM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I know this is an old thread, but I thought I would post a simpler solution for those that dont know.

Code:
Dim myLabel As Label= e.CommandSource.FindControl("myLabel")
 


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
Paging in gridview control VadimZ ASP.NET 2.0 Professional 8 February 17th, 2010 02:12 AM
How to put a button control in a GridView control ryan.webb ASP.NET 2.0 Basics 2 December 28th, 2007 05:26 AM
User Control in a GridView Colonel Angus ASP.NET 2.0 Basics 4 August 13th, 2007 10:28 AM
Gridview control parameter ~ kutel ASP.NET 2.0 Basics 0 July 22nd, 2007 08:37 PM
GridView Control jmyers@smurfit.com Pro Visual Basic 2005 2 March 14th, 2007 10:57 PM



All times are GMT -4. The time now is 07:11 PM.


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