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.Filter ASP.Net GridView using Session in C# and VB.Net<p>Hi <a class="username" rel="nid@patel"> nid@patel</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:GridView ID=&#34;gvDetails&#34; runat=&#34;server&#34;&gt; &lt;/asp:GridView&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Configuration; using System.Data; using System.Data.SqlClient;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data.Configuration Imports System.Data.SqlClient Imports System.Data</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session[&#34;Company&#34;] != null) { string emailid = Session[&#34;Company&#34;].ToString(); using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;conString&#34;].ConnectionString)) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = &#34;SELECT * FROM Table WHERE EmailId = @Email&#34;; cmd.CommandType = CommandType.Text; cmd.Connection = con; cmd.Parameters.AddWithValue(&#34;@Email&#34;, emailid); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); this.gvDetails.DataSource = dt; this.gvDetails.DataBind(); } } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not IsPostBack Then If Session(&#34;Company&#34;) IsNot Nothing Then Dim emailid As String = Session(&#34;Company&#34;).ToString() Using con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings(&#34;conString&#34;).ConnectionString) Dim cmd As SqlCommand = New SqlCommand() cmd.CommandText = &#34;SELECT * FROM Table WHERE EmailId = @Email&#34; cmd.CommandType = CommandType.Text cmd.Connection = con cmd.Parameters.AddWithValue(&#34;@Email&#34;, emailid) Dim sda As SqlDataAdapter = New SqlDataAdapter(cmd) Dim dt As DataTable = New DataTable() sda.Fill(dt) Me.gvDetails.DataSource = dt Me.gvDetails.DataBind() End Using End If End If End Sub</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/647243/Filter-ASPNet-GridView-using-Session-in-C-and-VBNet/https://www.aspforums.net:443/Threads/647243/Filter-ASPNet-GridView-using-Session-in-C-and-VBNet/Tue, 13 Aug 2019 04:15:22 GMT