Solved

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

Posted on 2006-10-26
2
2,618 Views
Last Modified: 2011-08-18
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?
0
Comment
Question by:cgipisani
2 Comments
 
LVL 6

Accepted Solution

by:
Niraj_Singh earned 250 total points
ID: 17818470

 could you tell me what code did you write for the PageIndexChanged event of the datagrid. it would be easier for me to help you then.

private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
      ur code here....      
}
0
 

Author Comment

by:cgipisani
ID: 17821599
I didn't have anything for that function.

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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now