locked
passing gridview cell value to another page RRS feed

  • Question

  • User1386166523 posted

    Hello,

    I have a GridView control on a Request2.aspx page. In the <Columns> section, there is a TemplateField showing project ids from the project table:

    <asp:TemplateField ItemStyle-HorizontalAlign="Left" ItemStyle-Width="20%" HeaderText="Project ID">
        <ItemTemplate>
            <asp:LinkButton ID="Lbtn_Select" runat="server" Text='<%# Eval("projectid") %>'
                ToolTip="Click To View Details" PostBackUrl="~/Request2Detail.aspx"></asp:LinkButton>
        </ItemTemplate>
    </asp:TemplateField>

    Gridview is populated by assigning datatable as datasource to gridview. The gridview shows project ids as links and the control transfers to Request2Detail.aspx page. In Request2Detail.aspx, I have to show information of the project id that was clicked. However, I have not been able to pass the clicked project id value to the Request2Detail.aspx. Lbtn_Select.Text contains the project id for each row of Gridview. I read that through PostBackUrl property, we can access all controls of the previous page using Request object such as TextBox1.Text = Request.Form["TextBox1"].ToString();

    However, projectid is a TemplateField within a gridview.

    Regards,

    Shehzad

    Friday, December 23, 2016 11:53 AM

Answers

  • User3690988 posted

    This assumes that there is no restriction in passing the projectid as a QueryString parameter.  Try this:

    PostBackUrl='<%# Eval("projectid", "~/Request2Detail.aspx?id={0}") %>'

    Then in the Request2Detail page, Request.QueryString("id);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 23, 2016 2:16 PM

All replies

  • User3690988 posted

    This assumes that there is no restriction in passing the projectid as a QueryString parameter.  Try this:

    PostBackUrl='<%# Eval("projectid", "~/Request2Detail.aspx?id={0}") %>'

    Then in the Request2Detail page, Request.QueryString("id);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 23, 2016 2:16 PM
  • User1386166523 posted

    Thanks a lot paindaasp. It worked perfectly with the following code:

    //Request2.aspx
    <ItemTemplate>
        <asp:LinkButton ID="Lbtn_Select" runat="server" Text='<%# Eval("projectid") %>'
            ToolTip="Click To View Details" PostBackUrl='<%# Eval("projectid", "~/Request2Detail.aspx?id={0}") %>'></asp:LinkButton>
    </ItemTemplate>
    
    //Request2Detail.aspx.cs
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Request.QueryString["id"]);
    }
    
    

    Regards,

    Shehzad

    Saturday, December 24, 2016 5:08 AM