0
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

1
  • Are you using <asp:boundfield in grid? Commented Sep 13, 2011 at 13:33

1 Answer 1

4

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";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.