开发者

Sorting the grid view in asp.net

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();
}

I am data binding a grid view and It displays the row based on the MsgID. I want it to display in descending order so that the new message gets displayed on the top of the grid


Change your query to do the sorting appropriately like so:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜