I've just started ASP.NET for real, and I was wondering if it is possible to use connection strings from Data Sources instead of hard-coding them. I've added my connection in Data Sources and it works, and I can also drag a table to a page in design mode, but I can't figure out how to access it in code. Here's what I get when I drag it in:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display.">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="xxx" HeaderText="xxx"
SortExpression="xxx" />
<asp:BoundField DataField="xxx" HeaderText="xxx"
SortExpression="xxx" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:xxxConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:xxxConnectionString1.ProviderName %>"
SelectCommand="SELECT xxx FROM xxx">
</asp:SqlDataSource>
<connectionStrings> <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /> <add name="xxxConnectionString1" connectionString="xxx" providerName="System.Data.SqlClient" /> </connectionStrings>But how do I get to xxxConnectionString1?