Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6966287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:10:20+00:00 2026-05-27T16:10:20+00:00

I have defined a SqlDataSource in my ASP code and I am trying to

  • 0

I have defined a SqlDataSource in my ASP code and I am trying to access it from my C# code-behind. I get an error that the source is unknown. What do I have to do so that I can access it from my code-behind?

C# code –

protected void OnEditingGridView1(object sender, GridViewEditEventArgs e)
{
    GridViewRow row = GridView1.Rows[e.NewEditIndex];
    int index = row.RowIndex;
    string ClientKey = GridView1.DataKeys[index].Values["ClientKey"].ToString();

    SqlDataSourceDebtor.SelectParameters.Clear();
    SqlDataSourceDebtor.SelectParameters.Add("clientKey", ClientKey);

}

ASP code –

            <EditItemTemplate>
                <asp:DropDownList ID="ddlDebtorName" runat="server" 
                    DataSourceID="SqlDataSourceDebtor" DataTextField="Name" 
                    DataValueField="DebtorKey">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSourceDebtor" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:AuditDevConnectionString2 %>" 
                    SelectCommand="sp_fc_vm_getDebtorList" SelectCommandType="StoredProcedure">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="GridView1" DefaultValue="0" Name="ClientKey" 
                            PropertyName="SelectedValue" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </EditItemTemplate>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:10:20+00:00Added an answer on May 27, 2026 at 4:10 pm

    The SqlDataSource is in an EditItemTemplate. That means there’ll be a SqlDataSource for each row of this GridView, Repeater—whatever this is.

    If you want to get the SqlDataSource for, say, the third row in your GridView, you’d want something like:

    gv.Rows[2].FindControl("SqlDataSourceDebtor") as SqlDataSource;
    

    EDIT – I did a quick test and this works fine:

        <asp:GridView runat="server" ID="gv">
            <Columns>
                <asp:BoundField DataField="str" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:DropDownList runat="server" DataTextField="name" DataValueField="id" DataSourceID="sqlId"></asp:DropDownList>
                        <asp:SqlDataSource runat="server" ID="sqlId" ConnectionString="Data Source=DevAdam;Initial Catalog=ZoomieRest;Integrated Security = true;"
                         SelectCommand="Select top 10 id, name from zoomiesql.subjects where userid = 7"></asp:SqlDataSource>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    

    Code Behind

        gv.DataSource = new[] { new { str = "A" }, new { str = "B" }, new { str = "C" } };
        gv.DataBind();
    
        var sqlSource = gv.Rows[2].FindControl("sqlId") as SqlDataSource;
        Response.Write(sqlSource.ConnectionString);
    

    This prints out the connection string for the embedded SqlDataSource.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have my SqlDataSource with a SelectQuery defined as follows: SELECT * FROM
I have defined a web service that will return the data from my mysql
I have defined a class to process a file but get the following error
I have defined a class A and derived a new class B from A
I have a project that is build up from several OSGi bundles. One of
I have defined a textbox with x:Name=txtMyTextBox inside UserControl called MyView. I've noticed that
I have a Crystal Report used in an ASP.NET web application that I've just
i have a gridview which is populating from sql datasource defined at designed, i
I have defined a custom error but if I test if custom error gets
I'm designing a Data Access layer for an C#/ASP.net application and I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.