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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:27:55+00:00 2026-05-24T23:27:55+00:00

I stumbled across this before and I know it is a common problem. One

  • 0

I stumbled across this before and I know it is a common problem. One related question is GridView is empty. But it does not solve my problem.

Ideally what I want is update my gridview depending on the value in a textbox when I click the ‘Find’ button. It does work for me in my other page. But I have some problem here. I have not changed any default parameters. Here is the gridview

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
    DataSourceID="SqlDataSource1" AutoGenerateColumns="False" 
    DataKeyNames="ID">
    <Columns>
        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
            ReadOnly="True" SortExpression="ID" />
        <asp:BoundField DataField="companyname" HeaderText="companyname" 
            SortExpression="companyname" />
        <asp:BoundField DataField="contactfirstname" HeaderText="contactfirstname" 
            SortExpression="firstname" />
        <asp:BoundField DataField="contactlastname" HeaderText="contactlastname" 
            SortExpression="lastname" />
        <asp:BoundField DataField="phonenumber" HeaderText="phonenumber" 
            SortExpression="phonenumber" />
        <asp:BoundField DataField="contactid" HeaderText="contactid" 
            SortExpression="contactno" />
    </Columns>
</asp:GridView>

In my “Find” Button click event. I am using this code

protected void btnFind_Click(object sender, EventArgs e)
{
    SqlDataSource1.DataBind(); /* Edit: I don't need this, I realized */
}

But it does not load anything. The whole gridview dos not appear. If I use select statement, the gridview does appear with results. I have tested my storedprocedure inside the gridview and it works the way it should. Don’t know what exactly could be the problem here? Anyone came across it?

I think I read somewhere if the stored procedure returns 0 results, gridview will not be displayed.

My SQLDataSource

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:MyDBconn %>" 
    SelectCommand="usp_GetContactNo" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:FormParameter DefaultValue="" FormField="txtCompanyName" 
            Name="companyname" Type="String" />
        <asp:FormParameter FormField="txtFirstName" Name="firstname" Type="String" />
        <asp:FormParameter FormField="txtLastName" Name="lastname" Type="String" />
        <asp:FormParameter FormField="txtPhone" Name="phone" Type="String" />
        <asp:FormParameter FormField="txtContactID" Name="contactNo" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

StoredProcedure is below. Note I might have changed some names above for security reasons but below is the original fields.

ALTER PROCEDURE [dbo].[usp_GetContactIDs] 
    -- Add the parameters for the stored procedure here
    @companyname varchar(255) = NULL, 
    @firstname varchar(255) = NULL,
    @lastname varchar(255) = NULL,
    @phone varchar(10) = NULL,
    @contactid varchar(15) = NULL
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    Declare @sql varchar(1000);



    set @sql = 'select ID, companyname,contactfirstname,contactlastname,phonenumber, contactid from oet WHERE ID is not null'

    if(@companyname is not null)
        set @sql = @sql + ' AND companyname = '''+ @companyname + '''';

    if(@firstname is not null)
        set @sql = @sql + ' AND contactfirstname = '''+ @firstname + '''';

    if(@lastname is not null)
        set @sql = @sql + ' AND contactlastname = '''+ @lastname + '''';

    if(@phone is not null)
        set @sql = @sql + ' AND phonenumber = '''+ @phone + '''';

    if(@contactid is not null)
        set @sql = @sql + ' AND contactid = '''+ @contactid + '''';


    exec (@sql)


END
  • 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-24T23:27:55+00:00Added an answer on May 24, 2026 at 11:27 pm

    It took me more than a day to solve it. The problem was Master pages. when I removed the master page from the page everything worked fine. What was happening is txtFirstName control was on the page, but it was never found since I was using a master page. As a result it was passing a null value every time. It did not produce any error (which is should), that made debugging very tricky.

    There were a bunch of other properties that you need to look at. Important ones are

    In SQL DataSource, configur DataSource, Parameter section : select the parameter and click on ‘show advance options’, ConvertEmptyStringToNull. You may need to change it to false.

    SQLDatasourc -> Properites -> CancelSelectOnNullParamter = change it to false

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

Sidebar

Related Questions

This is a problem one of our developers brought to me. He stumbled across
Searching something on SO, I stumbled across this question and one of the comments
I stumbled across this problem in F#. Suppose, I want to declare two types
I just stumbled across this question and I noticed the user is using some
I stumbled across this code and am too proud to go and ask the
I stumbled across this C code today. Can anyone tell me what the 'where'
I recently stumbled across this entry in the google testing blog about guidelines for
I just stumbled across this bug in some legacy code: class MyAPIHandler { private:
I've stumbled across this great post about validating parameters in C#, and now I
I'm currently learning Ruby and RoR and I stumbled across this declaration: link_to_remote(name, options

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.