but received with the error "The server tag is " /> but received with the error "The server tag is " /> but received with the error "The server tag is "/>

I wish to select the city name from tblCity Where the StateID will refer to the <%# Bind("StateID") %> but received with the error "The server tag is not well formed." Is there any missing part in my coding? Appreciate for helping. Thanks. Below is my code:

<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [CityName] FROM [tblCity] WHERE [StateID] = "+ '<%# Bind("StateID") %>' + ""></asp:SqlDataSource>
1

There are 1 best solutions below

0
Albert D. Kallal On

You can't use binding expressions in a sql paramter.

So you have to note or suggest where that value supposed to come from???

eg say like this:

<asp:SqlDataSource ID="SqlDataSource3" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    SelectCommand="SELECT [CityName] FROM [tblCity] WHERE [StateID] = @StateP">

    <SelectParameters>
        <asp:ControlParameter 
            ControlID="txtState" PropertyName="Text"
            Name="StateP" Type="String" DefaultValue="" />    
    </SelectParameters>
</asp:SqlDataSource>

So, in above we set @StateP parameter as type string, and set the control id on the page where the state is to come from (a text box control called txtState).

But you have that <%# -- and that type of expression is only for binding expressions - of which you don't have for sql parameters.

I guess we need more information where the value StateID is to come from.