locked
Pass Value of the hyperlinked field in a GridView to the textbox on the other page RRS feed

  • Question

  • User1288822499 posted

    Hi All,

    How can we fech a hyperlinked grid view data into a text box on the other page?

    I am trying some thing like this but couldn't get it working

     Page lastPage = (Page)Context.Handler;
     TextBoxRequestID.Text=lastPage.FindControl("GridView1.Rows.Cells[0].Value").ToString();

    GridView1 is on the other webPage.

    Friday, April 11, 2014 5:03 PM

Answers

  • User1918509225 posted

    Hi,

    About your problem,please try the solution below:

    1 Add a Row Commnand event to the GridView ,just like below:

    <asp:GridView onRowCommand="GvRowCommand" ID="GridView1" runat="server">
             <asp:TemplateField>
                   <ItemTemplate>                                                                    
                       <asp:LinkButton Text="Click" ID="LinkButton2" runat="server" 
                           CommandArgument='<%# Eval("SomeId") %>'/>                                                                                 </ItemTemplate>                                                            
    </asp:TemplateField>  
    </asp:GridView>  
    

    2  In the server side:

    protected void GvRowCommand(object sender, GridViewCommandEventArgs e)
       {
          var someId= e.CommandArgument;
          Response.Redirect("Target.aspx?id="+someId.Tostring(),false);
    }
    

    3 In the target page,you can try to use QueryString in page_load like below,set the value to textbox:

        TextBox1.Text=Request.QueyString[“id”];

    Hope it can help you.

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 13, 2014 10:47 PM