Gridview is not displayed when using stored procedure in SQLDatasource?

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.

Up vote 1 down vote favorite share g+ share fb share tw.

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 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 " SelectCommand="usp_GetContactNo" SelectCommandType="StoredProcedure"> 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 asp.net stored-procedures gridview sqldatasource link|improve this question edited Aug 19 '11 at 16:00 asked Aug 18 '11 at 21:05The crocodile hunter1,04314 81% accept rate.

– Tim Aug 18 '11 at 23:08 Yes, it is needed to update the grid view. – The crocodile hunter Aug 19 '11 at 3:39 correction: You are right DataBind() is not needed. – The crocodile hunter Aug 19 '11 at 15:51 can you post your SP please?

– emre nevayeshirazi Aug 19 '11 at 15:56 Stored Procedure posted. This works fine the regular way and inside SQL Datasource test query but not on the page. – The crocodile hunter Aug 19 '11 at 16:01.

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.

If you're using FindControl in C# then there shouldn't be a problem with finding the textbox name by id if it exist on the same page, so I don't where you think your problem was – Jake Aug 19 '11 at 18:24 I am not using any C# code. Everything is ASP. I am looking at $ operator now to fix findcontrol problem.

– The crocodile hunter Aug 19 '11 at 18:34.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions