如何将Session变量用于GridView的Select命令? [英] How to use Session variable into a Select command of a GridView?
本文介绍了如何将Session变量用于GridView的Select命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在* .aspx页面下有一个gridview SelectCommand,如下所示。
SelectCommand = SELECT * FROM [examConfig]
但是我需要使用访问的WHERE条件会话变量getTchId。我不知道如何使用它,我试过这个但不行。
SelectCommand = SELECT * FROM [examConfig] WHERE [tchId] =' +<%=( string )会话[ getTchId] %> + '
请有人帮助我。
解决方案
试试这个: -
使用SessionParameter和SelectParameters传递会话值
< asp:SqlDataSource < span class =code-attribute> ID = SqlDataSource2 runat = server
ConnectionString = <%
ConnectionStrings:yourConnection %>
SelectCommand = SELECT * FROM [examConfig] WHERE [tchId] = @getTchId >
< SelectParameters >
< asp:SessionParameter 名称 = 名称 SessionField = getTchId 类型 = 字符串 / >
< / SelectParameters >
< / asp:SqlDataSource >
尝试这可以帮到你
SelectCommand =SELECT * FROM [examConfig] WHERE [tchId] ='+ Session [getTchId ]的ToString()+';
I have a gridview SelectCommand under a *.aspx page like below.
SelectCommand="SELECT * FROM [examConfig] "
But I need to use a WHERE condition that access a session variable getTchId. I don't know how to use it, I have try this but not work.
SelectCommand="SELECT * FROM [examConfig] WHERE [tchId] = '" + <%= (string)Session["getTchId"] %>+ "'"
Please someone help me.
解决方案
try this:-
Use SessionParameter with SelectParameters to pass Session values
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%
ConnectionStrings:yourConnection %>" SelectCommand="SELECT * FROM [examConfig] WHERE [tchId]= @getTchId"> <SelectParameters> <asp:SessionParameter Name="Name" SessionField="getTchId" Type="String" /> </SelectParameters> </asp:SqlDataSource>
try this it may help you
SelectCommand="SELECT * FROM [examConfig] WHERE [tchId] = '" +Session["getTchId"].ToString()+"'";
这篇关于如何将Session变量用于GridView的Select命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文