Solved

Filter GridView with UserID

Posted on 2014-01-09
3
285 Views
Last Modified: 2014-01-14
Hi there

Pretty new to working in ASP.NET (VB) and have what I think is a simple question here but I have a GridView that I wish to apply a filter against the logged in UserID but I can't seem to get this for some reason.

Anyone able to offer any assistance on how I go about obtaining the UserID from the standard AspNet.Identity package which is what I'm using?

Driving me insane atm lol.

Any help appreciated as always guys.

Thanx
0
Comment
Question by:Steven O'Neill
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Rouchie earned 500 total points
ID: 39767991
You should filter the data before it reaches the GridView.  So, perhaps if you have a DataTable, you can do

Dim dv as New DataView(myDataTable)
dv.RowFilter = String.Format("ColumnToFilter = {0}", User.Identity.GetUserId().ToString)
myGridView.DataSource = dv.ToTable
myGridView.DataBind()

Open in new window

0
 
LVL 2

Author Comment

by:Steven O'Neill
ID: 39779217
This is what I ended up doing:

            <asp:SqlDataSource ID="SqlDataSource1" runat="server" OnSelecting="SqlDataSource1_Selecting" ConnectionString="<%$ ConnectionStrings:aspnet-WebSite1-13bb7ef4-4736-49de-9eb7-9b2d7393640dConnectionString1 %>" 
                SelectCommand="SELECT [Id], [OAS_ID], [CRM_VolGUID], [CRM_BusinessGUID], [CRM_BusinessName] FROM [YBSCRM_VolData] WHERE ([OAS_ID] = @NewUserID)">
                <SelectParameters>
                    <asp:Parameter Name="NewUserID" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>

Open in new window

and the code behind was:

Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
        e.Command.Parameters("@NewUserID").Value = User.Identity.GetUserId()
    End Sub

Open in new window

So you're comments about filtering the data proved very useful as this was my stumbling block.
0
 
LVL 2

Author Closing Comment

by:Steven O'Neill
ID: 39779219
Not the end code used but help point me in the direction I was going wrong.

Thanx
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now