how transfer connection string in ASCx to SharePoint web.cfg

In my sharepoint site, I have a child control that points to a ascx file.

I have a user control that has embeeded connection string code that will be displayed as a web part in my sharepoint site. The connection string is embeeded in the ASCX file.

Is there a way i can get the ascx file to run on my sharepoint site without the connectstring being in the ascx file.
I would keep connection strings in Web.cfg file. Is there a way to do this?

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="dg2.ascx.cs" Inherits="dg2" %>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=training;Initial Catalog=employeecars;User ID=dbuser;Password=Training45;"
    SelectCommand="SELECT [employee_id], [employee_name] FROM [Employees]"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
    DataTextField="employee_name" DataValueField="employee_id">
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="Data Source=training;Initial Catalog=employeecars;User ID=dbuser;Password=Training45;"
    SelectCommand="SELECT [car_license], [car_model] FROM [Cars] WHERE ([employee_id] = @employee_id)">
        <asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="employee_id"
            PropertyName="SelectedValue" Type="Int32" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
    DataSourceID="SqlDataSource2" ForeColor="#333333" GridLines="None">
    <RowStyle BackColor="#EFF3FB" />
        <asp:BoundField DataField="car_license" HeaderText="car_license" SortExpression="car_license" />
        <asp:BoundField DataField="car_model" HeaderText="car_model" SortExpression="car_model" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <AlternatingRowStyle BackColor="White" />

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can put the connection string in ConnectionStrings section in web.config of a SharePoint site.
In the code behind i.e. cs or .vb file you could read the connection string from web.config using ASP.Net configuration methods,
and then from the code use the Connection String for a Data Source. Apply this data source to the Grid
i.e. GridView1.DataSource = <Data Source created in Code>
Bind the data source i.e. execute the bind method (or dataBind) of the Grid

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dtotten800Author Commented:
more details example needed
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.