Solved

Filter GridView with UserID

Posted on 2014-01-09
3
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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