How do you ... SelectCommand="<%=strSQL%>"

  • Thread starter Thread starter googlegroup
  • Start date Start date
G

googlegroup

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionString:SalesDBConnectionString %>"
SelectCommand="<%=strSQL%>" />

In ASP.NET , how do you assign a dynamic value for the SelectCommand ?
You would think the above should work ?

Thanks...
 
I think it shouldn't work. A <%= %> block results in evaluating the content
and writing it into the output html stream. It is just a shortcut for
Response.Write(). The value of the SelectCommand attribute has nothing to do
with the client. It is rather used by asp.net on server side.

You can set it dynamically in code-behind.
 
Hi,

Thanks for the response.

I still can't figure this out though. How would one do a simple thing
like say select all records where CustomerID=@Customer ? -- or --
CustomerID=<%=CustomerID%>

I get that <%= %> won't work in ASP.NET , so how would you assign the
parameter a value assuming I have it stored as a Dim CustomerID as
String = ""

Thanks...
 
Hi,

Thanks for the response.

I still can't figure this out though. How would one do a simple thing
like say select all records where CustomerID=@Customer ? -- or --
CustomerID=<%=CustomerID%>

I get that <%= %> won't work in ASP.NET , so how would you assign the
parameter a value assuming I have it stored as a Dim CustomerID as
String = ""

Thanks...
 
<%= %> does work in asp.net. It is just doing exactly what it is supposed
to - sending the content of the block to the client's browser. And what you
want is pure server-side functionality.

What can help you is SqlDataSource.SelectParameters Property. Look up the
msdn or google for it.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
Back
Top