Pass Session value to HyperLink inside ASP.Net GridView Template Field

Last Reply 3 months ago By democloud

Posted 3 months ago

Hello Sir,

I'm trying to make a Gridview column itself as a hyperlink for regenerating reports for that particular row.

I have been using the below code for the same.

<asp:CommandField ShowSelectButton="True" ButtonType="Link" ShowHeader="True" SelectText="Report" ></asp:CommandField>

in Codebehind

 

 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int index = GridView1.SelectedRow.RowIndex;
        clientId = Convert.ToInt32(GridView1.Rows[index].Cells[0].Text);
        string role = obj.Encrypt(Convert.ToString(roleID));
        Response.Redirect("clientreport.aspx?ID=" + role + "&clientId= " + clientId);
    }

Using this I'm able to generate the reports but using my code one new column is getting generated, i want hyperlink to created from where onclick  report should be generated for particular row ID.

Thanks 

 

You are viewing reply posted by: democloud 3 months ago.
Posted 3 months ago

Hello Sir,

Below is the code for passing session variable in aspx page of hyperlink in gridview

public string GetUrl(object registerId, object client_name)
{
    string url ="~/report1.aspx?ID=" + role + "&registerId=" +       Server.UrlEncode(registerId.ToString());
    return url;
}

 

<asp:TemplateField> 
    <ItemTemplate> 
        <asp:HyperLink id="hlDetails2"  Runat="server" Text='<%# Eval("client_name") %>'
        NavigateUrl='<%# GetUrl(Eval("registerId"),Eval("client_name"))%>' /> 
    </ItemTemplate> 
</asp:TemplateField>
   

Thanks