ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Pass Session value to HyperLink inside ASP.Net GridView Template Field<p>Refer below article.</p> <h1 class="header"><a title="HyperLinkField ( HyperLink ) in ASP.Net GridView Example'a" href="https://www.aspsnippets.com/Articles/HyperLinkField-HyperLink-in-ASPNet-GridView-Example.aspx">HyperLinkField ( HyperLink ) in ASP.Net GridView Example</a></h1>https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/Tue, 11 Dec 2018 23:43:50 GMTPass Session value to HyperLink inside ASP.Net GridView Template Field<p>Hello Sir,</p> <p>I tried this example but not getting how to pass 2 parameters like&nbsp;</p> <p>&nbsp;</p> <pre class="brush: csharp"> Response.Redirect(&#34;clientreport.aspx?ID=&#34; + role + &#34;&amp;clientId= &#34; + clientId);</pre> <p>&nbsp;</p> <pre class="brush: csharp">&lt;asp:HyperLinkField DataTextField=&#34;Name&#34; DataNavigateUrlFields=&#34;Id&#34; DataNavigateUrlFormatString=&#34;~/Details.aspx?Id={0}&#34; HeaderText=&#34;Name&#34; ItemStyle-Width = &#34;150&#34; /&gt;</pre> <p>In the above example how to pass roleId and clientId, clientId will get from onclick of gridview row</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/Tue, 11 Dec 2018 23:54:39 GMTPass Session value to HyperLink inside ASP.Net GridView Template Field<p>Hey <a class="username" rel="democloud">democloud</a>,</p> <p>Please refer below article link.</p> <h1 class="header"><a title="Bind (Single or Multiple) QueryString Parameters to NavigateUrl of HyperLink using Eval function inside ASP.Net GridView'a" href="https://www.aspsnippets.com/Articles/Bind-Single-or-Multiple-QueryString-Parameters-to-NavigateUrl-of-HyperLink-using-Eval-function-inside-ASPNet-GridView.aspx">Bind (Single or Multiple) QueryString Parameters to NavigateUrl of HyperLink using Eval function inside ASP.Net GridView</a></h1>https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/Wed, 12 Dec 2018 00:49:09 GMTPass Session value to HyperLink inside ASP.Net GridView Template Field<p>Hello Sir,</p> <p>One parameter i need to pass from session, how to pass parameter from session.&nbsp;</p>https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/Wed, 12 Dec 2018 01:56:22 GMTPass Session value to HyperLink inside ASP.Net GridView Template Field<p>You are already data in session. So why you need to pass same value again. You can access the Session value in the destination page without passing in query string.</p>https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/Wed, 12 Dec 2018 02:04:48 GMTPass Session value to HyperLink inside ASP.Net GridView Template Field<p>Hello Sir,</p> <p>&nbsp;Getting error in below code "The server tag is not well formed."</p> <pre class="brush: csharp">&lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:HyperLink ID=&#34;HyperLink1&#34; runat=&#34;server&#34; NavigateUrl=&#39;&lt;%# string.Format(&#34;~/client_report.aspx?ID=Session{&#39;roleID&#39;}&amp;clientId={0}&#34;,HttpUtility.UrlEncode(Eval(&#34;clientId&#34;).ToString())) %&gt;&#39; Text=&#34;View Details&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt;</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/Wed, 12 Dec 2018 02:16:33 GMTPass Session value to HyperLink inside ASP.Net GridView Template Field<p>Hey <a class="username" rel="democloud"> democloud</a>,</p> <p>Please refer below sample.</p> <p>Please create rowdatabound event and find hyperlink id and pass values in navigate url..</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <p><strong>CS.aspx</strong></p> <pre class="brush: html">&lt;asp:GridView ID=&#34;GridView1&#34; HeaderStyle-BackColor=&#34;#3AC0F2&#34; HeaderStyle-ForeColor=&#34;White&#34; RowStyle-BackColor=&#34;#A1DCF2&#34; AlternatingRowStyle-BackColor=&#34;White&#34; AlternatingRowStyle-ForeColor=&#34;#000&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34; OnRowDataBound=&#34;GridView1_RowDataBound&#34;&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText=&#34;Id&#34; ItemStyle-Width=&#34;30&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:HyperLink runat=&#34;server&#34; NavigateUrl=&#39;&lt;%# Eval(&#34;Id&#34;, &#34;~/DetailsCS.aspx?Id={0}&#34;) %&gt;&#39; Text=&#39;&lt;%# Eval(&#34;Id&#34;) %&gt;&#39; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField=&#34;Name&#34; HeaderText=&#34;Name&#34; ItemStyle-Width=&#34;150&#34; /&gt; &lt;asp:BoundField DataField=&#34;Country&#34; HeaderText=&#34;Country&#34; ItemStyle-Width=&#34;150&#34; /&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:HyperLink ID=&#34;HyperLink1&#34; runat=&#34;server&#34; Text=&#34;View Details&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt;</pre> <p><span style="text-decoration: underline;"><strong>DetailsCS.aspx</strong></span></p> <p>&nbsp;</p> <pre class="brush: html">&lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Id&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:Label ID=&#34;lblId&#34; runat=&#34;server&#34;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Name&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:Label ID=&#34;lblName&#34; runat=&#34;server&#34;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;</pre> <p>&nbsp;</p> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data </pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <p><strong>CS.aspx.cs</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { Session[&#34;Id&#34;] = 1; DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3] { new DataColumn(&#34;Id&#34;), new DataColumn(&#34;Name&#34;), new DataColumn(&#34;Country&#34;) }); dt.Rows.Add(1, &#34;John Hammond&#34;, &#34;United States&#34;); dt.Rows.Add(2, &#34;Mudassar Khan&#34;, &#34;India&#34;); dt.Rows.Add(3, &#34;Suzanne Mathews&#34;, &#34;France&#34;); dt.Rows.Add(4, &#34;Robert Schidner&#34;, &#34;Russia&#34;); GridView1.DataSource = dt; GridView1.DataBind(); } } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { HyperLink hl = (HyperLink)e.Row.FindControl(&#34;HyperLink1&#34;); hl.NavigateUrl = String.Format(&#34;~/DetailsCS.aspx?Id={0}&amp;Name={1}&#34;, Session[&#34;Id&#34;].ToString(), e.Row.Cells[1].Text); } }</pre> <p><strong>DetailsCS.aspx.cs</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { lblId.Text = Session[&#34;Id&#34;].ToString(); lblName.Text = HttpUtility.UrlDecode(Request.QueryString[&#34;Name&#34;]); } }</pre> <p><strong>VB.Net</strong></p> <p><strong>VB.aspx.vb</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Session(&#34;Id&#34;) = 1 Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn(2) {New DataColumn(&#34;Id&#34;), New DataColumn(&#34;Name&#34;), New DataColumn(&#34;Country&#34;)}) dt.Rows.Add(1, &#34;John Hammond&#34;, &#34;United States&#34;) dt.Rows.Add(2, &#34;Mudassar Khan&#34;, &#34;India&#34;) dt.Rows.Add(3, &#34;Suzanne Mathews&#34;, &#34;France&#34;) dt.Rows.Add(4, &#34;Robert Schidner&#34;, &#34;Russia&#34;) GridView1.DataSource = dt GridView1.DataBind() End If End Sub Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then Dim hl As HyperLink = CType(e.Row.FindControl(&#34;HyperLink2&#34;), HyperLink) hl.NavigateUrl = String.Format(&#34;~/DetailsCS.aspx?Id={0}&amp;Name={1}&#34;, Session(&#34;Id&#34;).ToString(), e.Row.Cells(1).Text) End If End Sub</pre> <p><strong>DetailsVB.aspx.vb</strong></p> <pre class="brush: vb">Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then lblId.Text = Session(&#34;Id&#34;) lblName.Text = HttpUtility.UrlDecode(Request.QueryString(&#34;Name&#34;)) End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>&nbsp;Screenshot</strong></span></p> <p><span style="text-decoration: underline;"><strong><img src="https://imgur.com/kCKVfFM.gif" alt="" width="451" height="138" /></strong></span></p>https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/Wed, 12 Dec 2018 03:53:57 GMTPass Session value to HyperLink inside ASP.Net GridView Template Field<p>Hello Sir,</p> <p>How to pass session value in below code:</p> <pre class="brush: csharp">&lt;asp:TemplateField HeaderText=&#34;Id&#34; ItemStyle-Width=&#34;30&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:HyperLink runat=&#34;server&#34; NavigateUrl=&#39;&lt;%# Eval(&#34;Id&#34;, &#34;~/DetailsCS.aspx?Id={0}&#34;) %&gt;&#39; Text=&#39;&lt;%# Eval(&#34;Id&#34;) %&gt;&#39; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt;</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/Thu, 13 Dec 2018 02:22:16 GMTPass Session value to HyperLink inside ASP.Net GridView Template Field<p>Hey <a class="username" rel="democloud">democloud</a>,</p> <p>You can't pass session in aspx page of hyperlink.</p> <p>If you want to pass seesion please refer previous provided sample.</p>https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/Thu, 13 Dec 2018 02:51:01 GMTPass Session value to HyperLink inside ASP.Net GridView Template Field<p>Hello Sir,</p> <p>Below is the code for passing session variable in aspx page of hyperlink in gridview</p> <pre class="brush: csharp">public string GetUrl(object registerId, object client_name) { string url =&#34;~/report1.aspx?ID=&#34; + role + &#34;&amp;registerId=&#34; + Server.UrlEncode(registerId.ToString()); return url; }</pre> <p>&nbsp;</p> <pre class="brush: htl">&lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:HyperLink id=&#34;hlDetails2&#34; Runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;client_name&#34;) %&gt;&#39; NavigateUrl=&#39;&lt;%# GetUrl(Eval(&#34;registerId&#34;),Eval(&#34;client_name&#34;))%&gt;&#39; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; </pre> <p>Thanks</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/https://www.aspforums.net:443/Threads/304789/Pass-Session-value-to-HyperLink-inside-ASPNet-GridView-Template-Field/Fri, 14 Dec 2018 23:51:09 GMT