Link to home
Start Free TrialLog in
Avatar of cgipisani
cgipisani

asked on

Why does GridView paging not work when setting SqlDataSource SelectCommand attribute in code behind?

I have a GridView tied to a SqlDataSource.  TheSqlDataSource has SelectCommandType="Text".

The query string I'm looking to use will be dynamic.  For testing though, I'm trying "Select * from myTable".

I'm seeing two different behaviors for paging in the GridView depending on where I set the SelectCommand attribute of the SqlDataSource.  

1)  When I try to set SqlDataSource.SelectCommand in my code behind, the first page of data works, but any subsequent pages have no data.

2)  When I explicity put the SelectCommand in the GridView attributes, paging works fine.  This method doesn't work for me as I must be able to dynamically change the SelectCommand for the SqlDataSource.

Where am I failing with my code behind?
ASKER CERTIFIED SOLUTION
Avatar of Niraj_Singh
Niraj_Singh
Flag of India 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 cgipisani
cgipisani

ASKER

I didn't have anything for that function.

I solved my problem by using a stored procedure instead of text command.