Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 29th, 2012, 01:36 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile filter data based on logged in user's Id using EntityDataSource

Greetings to all,
I have a table named DailyCollection. On a page I have GridView, DetailsView and EntityDataSource. Both data bound controls are bound to EntityDataSource.

While inserting record I am saving logged in user's Id in table DailyCollection, but while retrieving records in GridView I have no Idea about how to filter data based on logged in user's id which is stored with every record in DailyCollection table.
So how I write where clause for EntityDataSource so that it filters data based on logged in user's Id?

Please suggest

Thanks
Reply With Quote
  #2 (permalink)  
Old July 30th, 2012, 10:55 AM
Authorized User
Points: 87, Level: 1
Points: 87, Level: 1 Points: 87, Level: 1 Points: 87, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2012
Location: New Mexico
Posts: 21
Thanks: 1
Thanked 2 Times in 2 Posts
Default

sophia,

A query is always performed on an Entity object or model, not really on the EntityDataSource. The easiest way to do what you're attempting is add a Where clause to the EntityDataSource similar to below and store the parameter specified in a Session object.

HTML Code:
<WhereParameters>
   <asp:SessionParameter Name="UserID" SessionField="UserID" />
</WhereParameters>
From there, in the Page_Load event of the code-behind, you might write something like this:

Code:
Session["UserID"] = [user_id_from_data_table]
Happy coding!
Reply With Quote
  #3 (permalink)  
Old July 30th, 2012, 12:03 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Hi, I am getting error "For the EntityDataSource, either Type or DbType (but not both) must be specified for each Parameter."

If I type DbType="Guid" then I get another error "'DailyCollection' is not a member of type 'ASPNETDBModel.DailyCollection' in the currently loaded schemas. Near simple identifier, line 6, column 4."

Please tell me what is the issue?
I am using this code.

Code:
<asp:EntityDataSource ID="EntityDataSource1" runat="server" 
        ConnectionString="name=ASPNETDBEntities" 
        DefaultContainerName="ASPNETDBEntities" EnableDelete="True" 
        EnableFlattening="False" EnableInsert="True" EnableUpdate="True" 
        EntitySetName="Clients" oninserting="EntityDataSource1_Inserting" 
        EntityTypeFilter="" Select="" Where="it.DailyCollection.UserId=@userId">
        <WhereParameters>
                <asp:SessionParameter Name="userId" SessionField="UserID" DbType="Guid" />
        </WhereParameters>
    </asp:EntityDataSource>
And code behind's Page_Load is

Code:
protected void Page_Load(object sender, EventArgs e)
    {
        Session["UserID"] = Membership.GetUser().ProviderUserKey;
     }
Reply With Quote
  #4 (permalink)  
Old July 30th, 2012, 01:02 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Ok I got it working,
I was making a mistake.
A little difference in code is required
Code:
Where="it.aspnet_Users.UserId=@userId">
Reply With Quote
  #5 (permalink)  
Old July 30th, 2012, 01:20 PM
Authorized User
Points: 87, Level: 1
Points: 87, Level: 1 Points: 87, Level: 1 Points: 87, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2012
Location: New Mexico
Posts: 21
Thanks: 1
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by sophia View Post
Ok I got it working,
I was making a mistake.
A little difference in code is required
Glad you got it working.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
store logged in user id in database from class file sophia ASP.NET 4 General Discussion 10 March 17th, 2012 06:56 PM
Displaying data based on user logged in Spider Visual Web Developer 2008 23 May 19th, 2010 01:44 PM
Web Service Get List ID with VBSCRIPT to filter on for UpdateListItems ismailc SharePoint Development 2 January 27th, 2010 08:32 AM
Setting logged in UserName to Session ID Admiral1701 ASP.NET 2.0 Professional 10 December 1st, 2006 10:35 AM
Filter Based Upon Logged In User LandOfToz BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 August 31st, 2004 12:24 PM



All times are GMT -4. The time now is 07:07 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.