如何使用对象数据源在列标题单击时对gridview进行排序 [英] How to sort the gridview on column header click, using object data source
本文介绍了如何使用对象数据源在列标题单击时对gridview进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个与ObjectDataSource绑定的Gridview.我想对列标题click..pls上的Gridview数据进行排序..如何做到这一点?
这是我的存储过程:
Hi,
I have a Gridview Binded with ObjectDataSource.I want to sort the Gridview data on column header click..pls show me..how to do that?
Here is my Stored Procedure:
ALTER PROCEDURE [dbo].[GetOnlineGiftingSurveyReport]
@FromDate as datetime,
@ToDate as datetime
AS
BEGIN
SELECT
A.Emp_ID,
EmpName=(B.First_Name+' '+ isnull(B.Middle_Name,'') +' ' +B.Last_Name),
D.designation as Designation,
A.Website_Access as [Have access to a website to pick and receive your gift?],
A.Gift_Selection as [Have variety of gift selections available to pick from?],
A.Shipping_Address as [You pick when and where you want your gift to arrive - enter shipping address],
A.Gift_Tracking as [Be able to track your gift?],
A.Submit_date
from OnlineGiftingSurvey A, mtw02ipdb03.PFSItedb.dbo.employees B,
mtw02ipdb03.PFSItedb.dbo.emp_designation C,
mtw02ipdb03.PFSItedb.dbo.designation_master D
where
convert(varchar(10),A.Submit_date,101) >=convert(varchar(10),@FromDate,101) and
convert(varchar(10),A.Submit_date,101) <= convert(varchar(10),@ToDate,101)
and A.Emp_ID=B.Domain_user_name
And C.emp_id=B.Emp_id
And D.desig_id=C.desig_id
END
我的DataLayer:
My DataLayer:
const string REPORT1 = "GetOnlineGiftingSurveyReport";
public GiftEntity[] GetReport(DateTime fDate, DateTime tDate)
{
SqlConnection sqlCon = new SqlConnection(Con);
SqlCommand sqlCmd = new SqlCommand(REPORT1, sqlCon);
sqlCmd.CommandType = CommandType.StoredProcedure;
try
{
OpenConnection(sqlCon);
sqlCmd.Parameters.Clear();
sqlCmd.Parameters.AddWithValue("@FromDate", fDate);
sqlCmd.Parameters.AddWithValue("@ToDate", tDate);
List<giftentity> result = new List<giftentity>();
SqlDataAdapter ada = new SqlDataAdapter(sqlCmd);
DataSet ds = new DataSet();
ada.Fill(ds);
foreach (DataRow reader in ds.Tables[0].Rows)
{
GiftEntity g = new GiftEntity();
g.Emp_ID = reader[0].ToString();
g.EmpName = reader[1].ToString();
g.Designation = reader[2].ToString();
g.Website_Access = reader[3].ToString();
g.Gift_Selection = reader[4].ToString();
g.Shipping_Address = reader[5].ToString();
g.Gift_Tracking = reader[6].ToString();
g.Submit_Date = DateTime.Parse(reader[7].ToString());
result.Add(g);
}
return result.ToArray();
}
catch (SqlException ex)
{
throw new AppSpecificException("Error while inserting the data", ex);
}
catch (Exception genEx)
{
throw new AppSpecificException("Error while inserting the data", genEx);
}
finally
{
CloseConnection(sqlCon);
}
}
Aspx.cs文件:
Aspx.cs file:
protected void Reportbtn_Click(object sender, EventArgs e)
{
GridView1.DataSource = ObjectDataSource1;
GridView1.DataBind();
}
推荐答案
您需要强制执行GridView_Sorting方法
You need to implent the GridView_Sorting method
这篇关于如何使用对象数据源在列标题单击时对gridview进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文