locked
Get GridView Row ID with.. RRS feed

  • Question

  • First of all, I'm 99% sure this is the totaly wrong place to post this! Anyway, I guess someone here can figure this out..

    I have this GridView in my .aspx page, and wish to navigate to an url according to the clicked row's ID. So for example when the user click the row which has the ID "ForumID3212329" the browser will navigate to, "http://mypage.com/forum/?ForumID3212329". I'm using JavaScript and .VB code to do this, and here is my code so far:

    Protected Sub GridView1_DataBound(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound  
    If e.Row.RowType = DataControlRowType.DataRow Then    
    ' MAKE ROW CLICKABLE    
                e.Row.ID = e.Row.Cells(0).Text ' Get ID from DataBase/An invisible cell (Don't comment)    

                e.Row.Attributes.Add("onClick""Select(this)"' Add the attribute to use JavaScript function "RowClick"   

    End If

    End Sub

    function Select(row)  
                    {  
                    window.location.href='http://mySite.com/forum/?' + 'GET ROW ID HERE!!';  
                    } 

    Tuesday, November 25, 2008 7:52 PM

Answers

  •  

    Hello Jake,

     

    Thank you for your post!  I would suggest posting your question in the ' MSDN Forums » Windows Forms » Windows Forms Data Controls and Databinding' located here:  http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=7&SiteID=1


    Have a great day!

    Thanks!


    SachinW Tier 2 Application Support Server and Tools Online Engineering Live Services Team
    • Proposed as answer by SachinW Wednesday, November 26, 2008 4:54 AM
    • Marked as answer by SachinW Wednesday, May 20, 2009 8:52 AM
    Wednesday, November 26, 2008 4:54 AM

All replies

  • Thank you.. I now used the last three hours figureing this out myself and finaly came up with a solution, I thought someone else on the Web could get use of this, so here you go:

    Simply change "Select(This)" to "Select('" & YourString/ID & "')") fixed the problem, guess I don't know very much about Java!

    If e.Row.RowType = DataControlRowType.DataRow Then  
                '###    MAKE ROW CLICKABLE      ###'  
    Dim StringAbs as String = e.row.ID  
                e.Row.Attributes.Add("onClick""Select('" & StringAbS.Text & "')")  
    End If 
     

    And The JavaScript is as following:

    function Select(row)  
                    {  
                    window.location.href='http://yourSite.com/forum/topicID=' + row;  
                    } 

    Tuesday, November 25, 2008 9:12 PM
  •  

    Hello Jake,

     

    Thank you for your post!  I would suggest posting your question in the ' MSDN Forums » Windows Forms » Windows Forms Data Controls and Databinding' located here:  http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=7&SiteID=1


    Have a great day!

    Thanks!


    SachinW Tier 2 Application Support Server and Tools Online Engineering Live Services Team
    • Proposed as answer by SachinW Wednesday, November 26, 2008 4:54 AM
    • Marked as answer by SachinW Wednesday, May 20, 2009 8:52 AM
    Wednesday, November 26, 2008 4:54 AM