---
title: "Based on logged username to filter data in Gridview"  
description: "Based on logged username to filter data in Gridview"  
author: "Munikumar G"  
published: 2012-02-15  
updated: 2012-02-25  
canonical: https://www.mindstick.com/forum/384/based-on-logged-username-to-filter-data-in-gridview  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Based on logged username to filter data in Gridview

[Post](https://www.mindstick.com/articles/12829/aspects-that-make-australia-post-shipping-extension-a-useful-tool) is removed by the User.

## Replies

### Reply by Chris Anderson

hi,\
\
If you want to display data of logged in user, you have to create the following sql query:\
\

```
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:workbookConnectionString %>"            SelectCommand="SELECT * FROM [clientDetails] WHERE ([id] = @id)">            <SelectParameters>                <asp:SessionParameter DefaultValue="" Name="id" SessionField="clientID"                     Type="Int32" />            </SelectParameters></asp:SqlDataSource>
```

\
In the above query a session field is created (id) in which you have to pass the id of user in order to display data in gridview.\
\
Thanks.

### Reply by Munikumar G

Hi,

This is my code

who has to login in the site display user details only on gridview.

please send me the code asap.

```
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ApptId" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True"><AlternatingRowStyle BackColor="White" /><Columns><asp:BoundField DataField="ClientId" HeaderText="ClientName" SortExpression="ClientId" /><asp:BoundField DataField="UserId" HeaderText="UserName"  SortExpression="UserId" /><asp:BoundField DataField="ApptTime" HeaderText="ApptTime" SortExpression="ApptTime" /><asp:BoundField DataField="ApptDate" HeaderText="ApptDate" SortExpression="ApptDate" /><asp:BoundField DataField="Duration" HeaderText="Duration" SortExpression="Duration" /><asp:BoundField DataField="MOM" HeaderText="MOM" SortExpression="MOM" /><asp:BoundField DataField="SalesExecutiveObjects" HeaderText="SalesExecutiveObjects" SortExpression="SalesExecutiveObjects" /><asp:BoundField DataField="SalesProjection" HeaderText="SalesProjection" SortExpression="SalesProjection" /><asp:BoundField DataField="NextFollowUpDate" HeaderText="NextFollowUpDate" SortExpression="NextFollowUpDate" /><asp:BoundField DataField="ExecutedClosingDate" HeaderText="ExecutedClosingDate" SortExpression="ExecutedClosingDate" /><asp:BoundField DataField="Remarks" HeaderText="Remarks" SortExpression="Remarks" /><asp:BoundField DataField="StatusId" HeaderText="StatusName" SortExpression="StatusId" /></Columns><FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /><HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /><PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /><RowStyle BackColor="#FFFBD6" ForeColor="#333333" /><SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /><SortedAscendingCellStyle BackColor="#FDF5AC" /><SortedAscendingHeaderStyle BackColor="#4D0000" /><SortedDescendingCellStyle BackColor="#FCF6C0" /><SortedDescendingHeaderStyle BackColor="#820000" /></asp:GridView><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MarketingSheetConnectionString %>" SelectCommand="SELECT*FROM [Appointment]" ></asp:SqlDataSource>Thanks
```

### Reply by Munikumar G

Post is removed by the User.

### Reply by Anonymous User

## Hi,

**In gridview display data as login username.**

## Thanks

MuniKumar,

What you trying to ask?\
You can paste you code here.

Here I am providing some links related with datagridview in asp.net which might be useful for you.

[1. GridView Decoration in ASP.NET](https://www.mindstick.com/Articles/805/gridview-decoration-in-asp-dot-net)

2. [GridView inside GridView in ASP.NET(Nested GridView)](https://www.mindstick.com/Articles/621/gridview-inside-gridview-in-asp-dot-net-nested-gridview)

3. [GridView Control in ASP.Net](https://www.mindstick.com/Articles/184/gridview-control-in-asp-dot-net)

Thanks


---

Original Source: https://www.mindstick.com/forum/384/based-on-logged-username-to-filter-data-in-gridview

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
