Link to home
Start Free TrialLog in
Avatar of dtotten800
dtotten800

asked on

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:DropDownList>
<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)">
    <SelectParameters>
        <asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="employee_id"
            PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
    DataSourceID="SqlDataSource2" ForeColor="#333333" GridLines="None">
    <RowStyle BackColor="#EFF3FB" />
    <Columns>
        <asp:BoundField DataField="car_license" HeaderText="car_license" SortExpression="car_license" />
        <asp:BoundField DataField="car_model" HeaderText="car_model" SortExpression="car_model" />
    </Columns>
    <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" />
</asp:GridView>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mo1one
mo1one
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dtotten800
dtotten800

ASKER

more details example needed