来自代码隐藏的 SQL 数据源/datagrid
我试图从身份验证 cookie 中提取用户名,并使用它向数据库发送请求,以使用 datagrid 或 sql 数据源提取该特定用户的信息。
我知道如何在前端(asp.net)实现sql数据源/datagrid,但我对如何在后面的代码中实现它感到困惑,以便我可以利用那里的用户名值
我用来拉取的代码用户名中是
IPrincipal p = HttpContext.Current.User;
string userid = p.Identity.Name;
谢谢
I am trying to extract the username from the authentication cookie and use it to send a request to the database to pull in the the information for that particular user using a datagrid or sql data source.
I know how to implement a sql datasource /datagrid in the front end (asp.net) but I am confused about how to do it in the code behind so that I can utilize the value of the username there
The code I am using to pull in the username is
IPrincipal p = HttpContext.Current.User;
string userid = p.Identity.Name;
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
** 这是你在后面的代码中放入的内容
datagrid1.datasource = MethodToGetTheDataSourceFromTheDatabase(p.Identity.Name);
datagrid1.databindI();
**
然后你只需让 MethodToGetTheDataSourceFromTheDatabase 执行你想要执行的 sql 语句并返回数据类型(数据集、数据适配器、列表<>等...)
** This is what you put in the code behind
datagrid1.datasource = MethodToGetTheDataSourceFromTheDatabase(p.Identity.Name);
datagrid1.databindI();
**
Then you would just have MethodToGetTheDataSourceFromTheDatabase execute the sql statement that you want executed and return the datatype(dataset, dataadapter, List<>, etc...)