Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a gridview SelectCommand under a *.aspx page like below.
C#
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.
C#
SelectCommand="SELECT * FROM [examConfig]   WHERE [tchId] = '" + <%= (string)Session["getTchId"] %>+ "'"
Please someone help me.
Posted
Updated 17-Sep-13 0:52am
v2

try this:-
Use SessionParameter with SelectParameters to pass Session values
XML
<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>
 
Share this answer
 
v2
Comments
sazzad37 17-Sep-13 6:43am    
Problem is, This is Under a *.aspx page.
TrushnaK 17-Sep-13 6:48am    
you didn't mention about aspx page
sazzad37 17-Sep-13 7:01am    
Sorry for that. Please help me to solve this.
TrushnaK 17-Sep-13 7:02am    
I have updated the solution. Is it ok....
sazzad37 17-Sep-13 7:12am    
Many many thank's. It's working.
try this it may help you


SelectCommand="SELECT * FROM [examConfig] WHERE [tchId] = '" +Session["getTchId"].ToString()+"'";
 
Share this answer
 
Comments
sazzad37 17-Sep-13 6:47am    
Problem is, This is Under a *.aspx page.
Salman622 17-Sep-13 6:55am    
are you using sqlDataSource
sazzad37 17-Sep-13 7:00am    
Yes

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