【问题标题】:Sorting the grid view in asp.net在 asp.net 中对网格视图进行排序
【发布时间】:2011-09-13 13:28:49
【问题描述】:
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 显示行。我希望它按降序显示,以便新消息显示在网格顶部

【问题讨论】:

  • 你在使用

标签: c# asp.net gridview


【解决方案1】:

更改您的查询以进行适当的排序,如下所示:

string MysqlStatement = "SELECT MsgID, MsgText, Title, RespondBy, ExpiresBy, OwnerName, Status FROM tbl_message WHERE tbl_user_tbl_organisation_OrganisationID = @Value1 order by MsgID desc";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多