0

I have a SqlDataSource that I am trying to modify in C# ASP.NET from my code behind page. The code in the page is:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="<%$ ConnectionStrings:TEST_SERVER %>" 
      ProviderName="<%$ ConnectionStrings:TEST_SERVER.ProviderName %>" 
</asp:SqlDataSource>

I want to dynamically modify the SelectCommand parameter for SqlDataSource1 but in the codebehind page it does not seem to be available.

Am I just doing it wrong?

1
  • 1
    Does it show data? If yes then the DataSet and Adapter are configured elsewhere. Be glad. Commented Mar 14, 2012 at 19:18

2 Answers 2

1

The select command will be there as soon as you add your ending '>' to your open tag.

Try this:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="<%$ ConnectionStrings:TEST_SERVER %>" 
      ProviderName="<%$ ConnectionStrings:TEST_SERVER.ProviderName %>">
</asp:SqlDataSource>    

Darn typos ;)

Sign up to request clarification or add additional context in comments.

1 Comment

Yup. That was the only issue.
0

Yes, it is available, just do:

 SqlDataSource1.SelectCommand="Select a , b, c from table_c";

The SelectCommand property is as string. Read the documentation here.

If you want to modify the select CommandType, use the SelectCommandType as so (stored proc):

SqlDataSource1.SelectCommandType=SqlDataSourceCommandType.StoredProcedure;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.