Solved

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

Posted on 2006-10-26
2
2,635 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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