How to redirect to another url when Edit (option in gridview) is clicked?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ewan
    New Member
    • Feb 2011
    • 18

    How to redirect to another url when Edit (option in gridview) is clicked?

    Hi

    Im using Visual Studio 2008, i have a gridview which gets data from an SQL table. I have added the Edit option which is part of gridview.
    The data has a primary key set.

    How do i redirect to another URL when the edit option is clicked.
    This action should also assign the primary key as a URL Parameter, causing only that specific record to show on the Edit page.

    I have gone through this article: http://bytes.com/topic/asp-net/answe...field-gridview
    However im not able to understand how to do this.
  • Ewan
    New Member
    • Feb 2011
    • 18

    #2
    For information:
    To add the edit button i have done the following:

    In GridView tasks go to:
    Edit Columns>Availab le Fields:>Command Field>Edit,Upda te,Cancel
    select Add

    This will display an edit button for each row on the GridView

    Comment

    • Ewan
      New Member
      • Feb 2011
      • 18

      #3
      I have found the resolusion @


      :)

      Comment

      • Ewan
        New Member
        • Feb 2011
        • 18

        #4
        :( UNFORTUNATELY - when i click on Edit it takes the value from the selected Row,
        so if i select the 2nd Row and click on edit for the 4th Row, i get the value for the 2nd Row and not the 4th.
        how do i select a row automatically when Edit option for that corresponsing row is clicked.
        Please help

        Comment

        • Ewan
          New Member
          • Feb 2011
          • 18

          #5
          i have updated the following in the Code Behind for the RowEditing event.
          it works just fine :)

          Code:
           
          Private Sub gridview1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gridview1.RowEditing
                  Session("wr_id") = gridview1.Rows(e.NewEditIndex).Cells(2).Text
                  Response.Redirect("EditRecord.aspx")
              End Sub
          what im doing here is moving the required data from the gridview into a Session
          (please refer to Article: http://bytes.com/topic/asp-net/insig...ween-web-pages on how to pass parameters using sessions)
          and then redirecting to the page where i need that required parameter to be displayed :).
          (You should have already updated the code behind to show the data captured in the session)
          Example: I updated the code behind for the EditRecord.aspx .vb as below
          Code:
              Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                  Dim ID As String = Session("wr_id")
          
                  lblReq.Text = "The parameter you have just transfered is " + ID
          
              End Sub

          Comment

          Working...