Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Getting data from a selected row in a gridview" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old July 30th, 2008, 10:10 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 174
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 1
peebman2000 is an unknown quantity at this point
Question Getting data from a selected row in a gridview

Hey everyone, Peeb here; I haven't posted anything in awhile. But i'm stumped on some small code.

Anyway I have a gridview that I'm using to display data from sql.
(gridview image here)
http://users3.nofeehost.com/peebman/...dviewimage.jpg

I have a email link to grab the email address from the 5th cell (text) and the
view information button to just grab the id#. The view information button works, but i'm having trouble with the email link button to grab the email text from which ever row the user selects.

I tried using this code below to get it to work, but is just posting back its not grabing the email text and I don't understand why this is not working.

Code:
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        Dim gridview As GridView = DirectCast(sender, GridView)

        If e.CommandName = "email" Then
            'Dim index As Object = e.CommandArgument
            'Response.Write(index)
            'Response.End()
            For i As Integer = 0 To GridView1.Rows.Count - 1

                If GridView1.SelectedIndex = i Then

                    Dim value As String = GridView1.Rows(i).Cells(5).Text
                    Response.Write(value)
                    Response.End()
                End If


            Next



            'Dim mail As String

            ''mail = GridView1.Rows(0).Cells(5).Text()
            'mail = CType(row.cells(2), DataControlFieldCell).text

            'Response.Write(mail)
            'Response.End()
        End If


        'For i As Integer = 0 To GridView1.Rows.Count - 1

        '    If GridView1.SelectedIndex = i Then


        '        Dim value As String = GridView1.Rows(i).Cells(5).Text
        '    End If
        'Next
    End Sub
Any suggestion or ideas on why this is not working. Any help would be appreciated, thanks.
Reply With Quote
Sponsored Links
  #2  
Old July 30th, 2008, 10:26 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default

Notice how they use GridViewRow in this example: GridView.RowCommand Event (System.Web.UI.WebControls)
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

Join our Folding team: DeveloperBarn Folding
Reply With Quote
The Following User Says Thank You to jmurrayhead For This Useful Post:
peebman2000 (July 30th, 2008)
  #3  
Old July 30th, 2008, 10:45 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 174
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 1
peebman2000 is an unknown quantity at this point
Talking reply

Thanks jmurrayhead, that worked. I must be like having stupid moments or something. Like I was researching this online, and I even reviewed the MSDN link you gave me, but for some reason it wasn't clicking. So I started coding it with a for loop thinking I needed to code it that way.

But looking at the article more thoroughly I see I should have followed the article. But it works now, thanks again.

Code:
  If e.CommandName = "email" Then

            Dim index As Integer = Convert.ToInt32(e.CommandArgument)
            Dim row As GridViewRow = GridView1.Rows(index)

            'Dim item As New ListItem()
            'item.Text = Server.HtmlDecode(row.Cells(5).Text)
            Dim value As String = Server.HtmlDecode(row.Cells(5).Text)



            Response.Write(value)
            Response.End()

        End If
Quote:
Originally Posted by jmurrayhead View Post
Notice how they use GridViewRow in this example: GridView.RowCommand Event (System.Web.UI.WebControls)

Last edited by peebman2000; July 30th, 2008 at 10:51 AM. Reason: edit
Reply With Quote
  #4  
Old July 31st, 2008, 12:18 PM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default

Cheers mate, glad I could help
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The data source 'ObjectDataSource1' does not support sorting with IEnumerable data Shem .Net Development 5 June 25th, 2008 08:07 AM
update gridview dynamically peebman2000 .Net Development 27 May 8th, 2008 10:03 PM
add additional footer to gridview peebman2000 .Net Development 13 May 2nd, 2008 01:50 PM
[ASP.Net/General] Create ToolTip for GridView Header jmurrayhead Code Samples 0 March 21st, 2008 02:26 PM


All times are GMT -4. The time now is 08:03 PM.



Content Relevant URLs by vBSEO 3.2.0