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
Solved

Filter GridView with UserID

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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