Mark
Mark

Reputation: 2760

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

Upvotes: 0

Views: 169

Answers (1)

Icarus
Icarus

Reputation: 63956

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";

Upvotes: 4

Related Questions