Hi Dale,
From your description, you're using GridView+SqlDataSource control to
display some data and have enabled sorting on the GridView. Also, you
programmtically set the SqlDataSource.SelectCommand instead of set it
statically in aspx. However, you find that if you click header link in
GridView to sort the data, the Gridview will become empty , correct?
Based on my experience, since you programmticaly set the "SelectCommand",
my first thought is that your code only set the "SelectCommand" at the
initial page request such as below:
===================
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlDataSource1.SelectCommand = "SELECT [id], [name], [price]
FROM [numtable]";
}
}
=======================
If this is the case, you should remove the "IsPosback" detection and make
sure you set the Select command in every request. e.g.
===================
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource1.SelectCommand = "SELECT [id], [name],
[price] FROM [numtable]";
}
===================
Thus, the GridView's sorting will work correctly. Please have a test and
let me know whether it works.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?QnJhc3NpY2FOaWdyYQ==?= said:
Subject: SqlDataSource and GridView sorting
Date: Wed, 16 Jul 2008 13:53:02 -0700
Greetings,
I have an asp.net 2.0 application that uses a sqldatasource to populate a
gridview. The sqldatasource.selectcommand is set programatically in the page
load function (the declaration in the .aspx file does not specify a select
command).
The grid loads normally but when you try to sort on any of the columns, the
gridview goes blank (as though it contained no records).
If I move the select command into the sqldatasource declaration in the .aspx
file then it sorts normally.
Since the select command must be set programatically based on user selection
criteria I cannot use the declarative approach.
What am I missing? Do I need to use separate gridviews for each subset of
the data (the select command always returns the same columns) in order to get
sorting to work?
Please advise.
Dale