Solved

Filter GridView with UserID

Posted on 2014-01-09
3
290 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need syntax help building hyperlink 2 53
Why use this lambda? 12 95
YouTube API get the Video Tags - vb.net 7 51
Multi-Column Repeater 3 39
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

732 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