Gridview可以在多用户应用程序中显示特定登录用户的数据 [英] Is is possible for Gridview to display data of particular logged in user in multiuser application

查看:198
本文介绍了Gridview可以在多用户应用程序中显示特定登录用户的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于多用户应用程序,例如假设许多用户存储的基于Web的项目列表

Gridview是否可以显示与特定登录用户有关的数据.

同样,当用户登录时,他将被重定向到具有Gridview控件的页面,该控件

从数据库中获取并显示与该特定登录用户有关的数据,并仅向他显示他的数据.

就像为这些表假设的一样-

登录表>>>

用户名|密码
------ | --------
------ | --------
------ | --------
------ | --------
------ | --------
(其中userid是主键)



产品表>>< br/>
产品编号|产品名称类别|用户名
---------- | ------------- | -------------- | -------
---------- | ------------- | -------------- | -------
---------- | ------------- | -------------- | -------
---------- | ------------- | -------------- | -------
---------- | ------------- | -------------- | -------
---------- | ------------- | -------------- | -------
---------- | ------------- | -------------- | -------
---------- | ------------- | -------------- | -------
(其中ProductId是主键,而Userid是外键)


在这里,我希望Gridview从Product表中按照登录的User(Userid)获取数据,并显示他或她的
仅限产品.

我需要什么概念来实现这一目标.我是否还需要参加会议?

如果有人可以提供帮助并在其上写文章,这将非常有帮助.

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.

推荐答案

步骤:

1.在会话中存储用户ID.
2.在从db进行gridview数据获取时,使用查询作为从user_id =(session中的user_id)表中选择列.
3.将数据绑定到Gridview并完成.
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.


您只需要查询产品表并将登录的用户ID 传递给查询参数.

以下查询是您所需要的.
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.
SELECT ProductID, Productname, category
FROM
    ProductTable
WHERE
    UserId = @LoggedInUserId


您需要使用ADO.NET对象并使用SQLCommand类,然后使用此查询对其进行初始化.
您指定参数,然后将登录User Id"作为参数传递.

请参考-为命令添加参数 [


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.


这篇关于Gridview可以在多用户应用程序中显示特定登录用户的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆