Solved

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

Posted on 2006-10-26
2
2,625 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# GridRow get Old/New Value 1 55
asp.net mvc input file 2 32
Auto refresh part of an MVC5 View 7 63
Class object 2 28
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

863 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

18 Experts available now in Live!

Get 1:1 Help Now