vb.net 将会话变量传递给 asp:gridview 的 sqldatasource select 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14042907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:41:15  来源:igfitidea点击:

pass session variable into asp:gridview's sqldatasource select command

sql.netvb.net

提问by squinny

I am currently having trouble trying to get a select command with a session variable in my asp gridview. I have been looking on here and other sites and have not really came across much. It's got to be a simple fix that i just have not came across yet. Here is my code

我目前在尝试在我的 asp gridview 中使用会话变量获取选择命令时遇到问题。我一直在看这里和其他网站,并没有真正遇到太多。它必须是一个简单的修复,我只是还没有遇到过。这是我的代码

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ConnectionStrings:mySql_Connection %>"
                    SelectCommand =  "Select [Username], [Name] FROM UserPassword WHERE CustID = '" & session("CustID") & "'>
                </asp:SqlDataSource>

I'm not even sure if that is close to correct or not. I get the server tag is not well formed. Or invalid syntax. Can someone show how to do this. I've been stuck on this and its really bugging me.

我什至不确定这是否接近正确。我明白了the server tag is not well formed。或者无效的语法。有人可以展示如何做到这一点。我一直被困在这个问题上,它真的困扰着我。

回答by ajp

You can use Session Paramter

您可以使用会话参数

<asp:SqlDataSource ConnectionString="<%$ConnectionStrings:mySql_Connection %>"
                SelectCommand =  "Select [Username], [Name] FROM UserPassword WHERE CustID     = @CustID>
 <SelectParameters>
  <asp:SessionParameter Name="CustID" SessionField="CustID"
   DefaultValue="0" />

 </SelectParameters>
</asp:SqlDataSource>

You can refer the below link also: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sessionparameter.aspx

您也可以参考以下链接:http: //msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sessionparameter.aspx