• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Filter GridView with UserID

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
Steven O'Neill
Asked:
Steven O'Neill
  • 2
1 Solution
 
RouchieCommented:
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
 
Steven O'NeillSolutions ArchitectAuthor Commented:
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
 
Steven O'NeillSolutions ArchitectAuthor Commented:
Not the end code used but help point me in the direction I was going wrong.

Thanx
0

Featured Post

Industry Leaders: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now