Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For a multi-user application , like suppose a web based item list stored by many users

Is it possible for Gridview to display data related to particular Logged in user.

Also when the user Logs in , he gets redirected to a page with Gridview control that

fetches and shows data related to that particular logged in user from database and displays him his data only.

Like suppose for these tables -

Login Table>>>

Userid | Password
------ | --------
------ | --------
------ | --------
------ | --------
------ | --------
(where userid is Primary key)

and

Product Table>>>

ProductID | Productname | category | Userid
----------|-------------|----------|-------
----------|-------------|----------|-------
----------|-------------|----------|-------
----------|-------------|----------|-------
----------|-------------|----------|-------
----------|-------------|----------|-------
----------|-------------|----------|-------
----------|-------------|----------|-------
(where ProductId is primary key and Userid is Foreign key)


Here i want Gridview to fetch data as per logged in User(Userid) from the Product table and display his or her
Products only.

What concept i'll be needing for this to make happen. Will i need Sessions also in this ?

If someone can Help and make an article on it please it will be very helpful.
Posted
Updated 18-Jan-14 2:47am
v2

Steps:

1. Store userid in a session.
2. while datafetch from db for gridview,use query as "select Columns from table whjere user_id=(user_id in session).
3. Bind data to Gridview and done.
 
Share this answer
 
v2
You just need to query to Product Table and pass logged in User Id as a parameter to the query.

The following query is something what you need.
SQL
SELECT ProductID, Productname, category
FROM
    ProductTable
WHERE
    UserId = @LoggedInUserId

You need to use ADO.NET objects and use SQLCommand Class and initialize that using this query.
You specify parameter and pass the Logged in User Id as a parameter.

Refer - Adding Parameters to Commands[^]

For User Id, you can use Session to store and retrieve.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900