在asp.net中排序网格视图
本文关键字:网格 视图 排序 asp net | 更新日期: 2023-09-27 18:08:22
private void BindGridView(string field)
{
string userName = field;
//Get OrganisationID from user Table
string OrgIdQueryText = "SELECT tbl_organisation_OrganisationID FROM tbl_user WHERE Email ";
int newOrgID = Convert.ToInt32(server.performQuery(OrgIdQueryText, userName, MySqlDbType.VarChar));
MySqlCommand command = new MySqlCommand();
DataSet ds = new DataSet();
string MysqlStatement = "SELECT MsgID, MsgText, Title, RespondBy, ExpiresBy, OwnerName, Status FROM tbl_message WHERE tbl_user_tbl_organisation_OrganisationID = @Value1";
using (server)
{
MySqlParameter[] param = new MySqlParameter[1];
param[0] = new MySqlParameter("@value1", MySqlDbType.Int32);
param[0].Value = newOrgID;
command.Parameters.AddWithValue("@Value1", newOrgID);
ds = server.ExecuteQuery(CommandType.Text, MysqlStatement, param);
}
Grid_Messagetable.DataSource=ds;
Grid_Messagetable.DataBind();
}
我是数据绑定一个网格视图,它显示基于MsgID的行。我希望它按降序显示这样新消息就会显示在网格的顶部
更改您的查询以进行适当的排序,如下所示:
string MysqlStatement = "SELECT MsgID, MsgText, Title, RespondBy, ExpiresBy, OwnerName, Status FROM tbl_message WHERE tbl_user_tbl_organisation_OrganisationID = @Value1 order by MsgID desc";