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

Last Reply one month ago By democloud

Posted one month 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 

 

Posted one month 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