protected void RadGridOutbox_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "Read")
            {
                GridDataItem dataItem    = e.Item as GridDataItem;
                string       strKeyValue = dataItem.GetDataKeyValue("M_MessageId").ToString();

                /*
                 * check if the message has alreaDY been read by user. If yes, then do not update DB.
                 * Else if not read then update DB flag.
                 */
                tblMessageHeaders.Visible = true;
                DataSet dsOutbox = (DataSet)ViewState["dsOutbox"];
                msgBo = new MessageBo();
                string strMessage = msgBo.GetMessage(Convert.ToInt64(strKeyValue));

                foreach (DataRow dr in dsOutbox.Tables[0].Rows)
                {
                    if (dr["M_MessageId"].ToString() == strKeyValue)
                    {
                        lblMessageContent.Text      = strMessage;
                        lblRecipientsContent.Text   = dr["Recipients"].ToString();
                        lblSubjectContent.Text      = dr["Subject"].ToString();
                        lblSentContent.Text         = dataItem["Sent"].Text;
                        ViewState["ReadMessRecpId"] = strKeyValue;
                        break;
                    }
                }
            }
        }
        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "Read")
            {
                #region Look into performance enhancement as multiple calls are made to DB

                GridDataItem dataItem    = e.Item as GridDataItem;
                string       strKeyValue = dataItem.GetDataKeyValue("MR_MessageRecipientId").ToString();
                string       strMsgId    = dataItem.GetDataKeyValue("M_MessageId").ToString();

                /*
                 *      check if the message has alreaDY been read by user. If yes, then do not update DB.
                 *      Else if not read then update DB flag.
                 */
                tblMessageHeaders.Visible = true;
                DataSet dsInbox = (DataSet)ViewState["dsInbox"];
                msgBo = new MessageBo();
                string strMessage = msgBo.GetMessage(Convert.ToInt64(strMsgId));

                foreach (DataRow dr in dsInbox.Tables[0].Rows)
                {
                    if (dr["MR_MessageRecipientId"].ToString() == strKeyValue)
                    {
                        lblMessageContent.Text      = strMessage;
                        lblSenderContent.Text       = dr["Sender"].ToString();
                        lblSubjectContent.Text      = dr["Subject"].ToString();
                        lblSentContent.Text         = dataItem["Received"].Text;
                        ViewState["ReadMessRecpId"] = strKeyValue;
                        break;
                    }
                }

                if (!Boolean.Parse(dataItem["ReadByUser"].Text))
                {
                    // If message is read first time, update DB that the message is read.
                    Int64 intRecipientId = Int64.Parse(strKeyValue);
                    bool  blResult       = false;
                    // update DB with read flag
                    msgBo    = new MessageBo();
                    blResult = msgBo.UpdateMessageReadFlag(intRecipientId);

                    if (blResult)
                    {
                        // this should retrieve only the flag values and update the existing dataset which is stored in the cache with new flag values.
                        RadGrid1.Rebind();
                    }
                }

                #endregion
            }
        }