Hello i am trying to email the radgrid but i am unable to send it.
Its giving me error when i am trying to change it into Html.
Here is my code.
I am getting the Exception at p.DesignerInitialize() method saying Request is not available in this context.... When i am using the normal Gridview i have no problem at all for sending it... But when trying to radgrid its throwing this exception.
Its giving me error when i am trying to change it into Html.
Here is my code.
| public void SendPMRSetupGrid(string FromEmail, string ToEmail, string Subject, RadGrid Gridview1) |
| { |
| MailMessage MessageToSend = new MailMessage(FromEmail, ToEmail); |
| MessageToSend.IsBodyHtml = true; |
| MessageToSend.Subject = Subject; |
| MessageToSend.Body = GridViewToHtml(Gridview1); |
| this.Send(MessageToSend); |
| } |
| private string GridViewToHtml(RadGrid gv) |
| { |
| Page p = new Page(); |
| p.EnableEventValidation = false; |
| RadScriptManager ScriptManag = new RadScriptManager(); |
| HtmlForm hf = new HtmlForm(); |
| p.Controls.Add(hf); |
| hf.Controls.Add(ScriptManag); |
| hf.Controls.Add(gv); |
| StringBuilder SB = new StringBuilder(); |
| StringWriter stringWrite = new StringWriter(SB); |
| HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); |
| p.DesignerInitialize(); |
| p.RenderControl(htmlWrite); |
| p = null; |
| return SB.ToString(); |
| } |