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 8791159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:48:17+00:00 2026-06-13T22:48:17+00:00

My scenario is a Gridview which is bound to a stored procedure using asp:SQLDataSource.

  • 0

My scenario is a Gridview which is bound to a stored procedure using asp:SQLDataSource. This was quickly done using the wizard where i selected the SP and all data was dispalyed.
The SP was created in such a way that it contains 4 parameters. When such parameters are null, they will return all values in the query.

I have created 3 textboxes and a dropdown list to populate these parameters, binding them to a button in an attempt to create a search functionality. I have tried many ways and methods, especially by research on this site but none seem to work. I cant quite find my issue so I appreciate any help on the matter. Below is my code.

<asp:SqlDataSource ID="sqlSourceID" runat="server" ConnectionString="<%$ ConnectionStrings:DBCONNSTRING%>"
            SelectCommand="storedProcedureName" SelectCommandType="StoredProcedure">                
        </asp:SqlDataSource>

The above is the SQL stored procedure bind.

I have attemtped to bind the controls as parameters for the SQL server. Prior to this code, the page used to load all records fine without search parameters as the SP was assuming a null value. Now nothing loads.

            <SelectParameters>
                <asp:ControlParameter ConvertEmptyStringToNull="true" ControlID="textBox1" PropertyName="Text" Name="1" Type="DateTime" />
                <asp:ControlParameter ConvertEmptyStringToNull="true" ControlID="textBox2" PropertyName="Text" Name="2" Type="DateTime" />
                <asp:ControlParameter ConvertEmptyStringToNull="true" ControlID="textBox3" PropertyName="Text" Name="3" Type="String" />
                <asp:ControlParameter ConvertEmptyStringToNull="true" ControlID="ddl1" PropertyName="SelectedText" Name="4" Type="String" />
            </SelectParameters>

Where the Control ID represents the textbox ID

Below is my code behind.

        sqlSourceID.SelectParameters["textbox1"].DefaultValue = this.textbox.Text;
        sqlSourceID.SelectParameters["textbox2"].DefaultValue = this.textbox1.Text;
        sqlSourceID.SelectParameters["textbox3"].DefaultValue = this.textbox2.Text;
        sqlSourceID.SelectParameters["ddl1"].DefaultValue =    Convert.ToString(this.ddl.SelectedText);

Well that is my problem. I need to find a way to pass parameters from the textboxes when the Search Button is clicked and assume null on page load or if nothing is written.

Thanks to all those who contribute in advance.

  • 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-06-13T22:48:18+00:00Added an answer on June 13, 2026 at 10:48 pm

    I don’t guarantee that this will solve the problem, but there are three things I see that look problematic:

    1. You gave the values 1, 2, and 3 to the Name property of your asp:ControlParameter tags. Unless the stored procedure you’re calling actually has parameters named @1, @2, and @3, you need to change those names to those of the parameters of the stored procedure you want to map to.

    2. Similarly, in your code-behind, you use the control names to look up the parameters of your SqlDataSource.SelectCommand, like so:

      sqlSourceID.SelectParameters["textbox1"].DefaultValue = this.textbox.Text;
      

      But “textbox1” is not the name of your stored procedure parameter. As you have written it, @1 is the name of that parameter. If you keep the names 1, 2, and 3, you should do your parameter setting like this:

      sqlSourceID.SelectParameters["1"].DefaultValue = this.textbox.Text;
      
    3. But I don’t think you’re supposed to need to set the values of the parameters in code-behind at all. That’s the point of the ControlParameter: it takes the value of a control property and assigns that to the command parameter. Here are some links that might help: Selecting Data Using the SqlDataSource Control and ASP.NET DetailsView and ControlParameter Example.

    I hope this helps.

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

Sidebar

Related Questions

I have this scenario. An ascx contains this GridView: <asp:GridView ID=dataTable runat=server > <Columns>
I have a gridview which uses a stored procedure with session[UserName] as a parameter
I am learning ASP.NET and I have a master-detail scenario using two GridViews in
I have this scenario where I want to share the column size among all
This is the XAML: <ListView.View> <GridView> <GridViewColumn DisplayMemberBinding={Binding Path=ScenarioName} Header=Scenario Name /> <GridViewColumn DisplayMemberBinding={Binding
Here's the scenario: I have an asp.net webpage which displays dynamic data in a
I have this GridView that have it's DataSource as a list of previously selected
Scenario first :- I'm using Entity Framework to do some queries, to build my
Scenario While using the Maven Ant Task artifact:deploy , I'm encountering the error java.lang.OutOfMemoryError:
Consider a web page having grid-view connected to SqlDataSource having all permission to insert

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.