Updating messages from a list of messages
Not sure if it's "optimized", but here's something of a simplification:

    protected void grdMessage_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string messageIdString = Request["MessageID"];
        int messageId = messageIdString == null ? 0 : Convert.ToInt16(messageIdString);

        using (DataSet mdsRedirect = new DataSet())
        {
            DataTable table = mdsRedirect.Tables[0];
            string updateMessageText = ((TextBox)grdMessage.Rows[e.RowIndex].FindControl("txtupdMessage")).Text;

            mdsRedirect.ReadXml(st);
            table.DefaultView.RowFilter = messageId == 0 ? table.DefaultView.RowFilter : "MessageID=" + messageId;
            if ((messageId != 0) &amp;&amp; (table.DefaultView.Count &gt; 0))
            {
                // Find specific item from XML and set updated value
                table.DefaultView[0]["MessageText"] = updateMessageText;
                table.DefaultView.RowFilter = string.Empty;
            }
            else
            {
                table.Rows[e.RowIndex]["MessageText"] = updateMessageText;
            }

            grdMessage.EditIndex = -1;
            mdsRedirect.WriteXml(st);
        }

        getxml(); // read XML file and bind it
    }