Search code examples
ajaxasp.net-mvcsqldatasource

asp.net sqldatasource parsing errors


The sqldatasource is giving me parse errors and i can't figure out why. I should say i'm working on an old version of NopCommerce. This is the error message i'm getting:

Type 'System.Web.UI.WebControls.SqlDataSource' does not have a public property named 'Type'.

This is the code generating the error:

<asp:SqlDataSource Type="button" ID="CustomerSearch" class="adminButtonBlue" runat="server" OnClick="btnImportXLS_Click" ValidationGroup="ExportXLS" ConnectionString ="<%$ ConnectionStrings:ConnectionString" %>"/>

Am i missing something in the sqldatasource-tag? Also, what is the purpose of the connectionstring and what should i put there, the same connaction name as in the connection.config file?

Thanks!


Solution

  • See the MSDN documentation on the SqlDataSource control.

    First off, there is no "Type" attribute. So you'll need to remove that. The SqlDataSource doesn't render a visible control at all, it's just for providing data / data operations to databound ASP.NET controls (like GridView,, FormView, etc).

    For the same reason, you don't have / need Onclick, class, or ValidationGroup attributes.

    This will not cause you parser errors:

    <asp:SqlDataSource ID="CustomerSearch" runat="server" 
        ConnectionString ="<%$ ConnectionStrings:yourConnectionString" %>"/>
    

    Where "yourConnectionString" above is a connection string name from your web.config file.

    However, it seems like you have a fundamental misunderstanding about what this control is to be used for. Check out this MSDN article for a great overview, and links to tutorials:

    SqlDataSource Web Control Overview.