Hi,
I am attempting to extract the HTML markup from a RadGrid, but I am having a problem. Specifically, when the
I am attempting to extract the HTML markup from a RadGrid, but I am having a problem. Specifically, when the
grd.RenderControl(htmlWriter)
line is executed, an error is being thrown stating that the GridLinkButtons must be placed within a form tag. My goal is to extract the HTML markup of the header columns and grid data items only - if this approach won't work, then I will probably have to look into a technique that will iterate each row of the grid and manually write the HTML (I'd like to avoid this if at all possible). Here is the code that I have at this point:
public static string ConvertRadGridToHTML(ref Telerik.Web.UI.RadGrid grd)
{
var stringwriter = new StringWriter();
var htmlWriter = new HtmlTextWriter(stringwriter);
string result;
try
{
htmlWriter.RenderBeginTag(HtmlTextWriterTag.Html);
htmlWriter.RenderBeginTag(HtmlTextWriterTag.Body);
grd.RenderControl(htmlWriter);
htmlWriter.RenderEndTag();
htmlWriter.RenderEndTag();
htmlWriter.Flush();
result = htmlWriter.ToString();
}
catch
{
result = String.Empty;
}
finally
{
htmlWriter.Close();
stringwriter.Close();
}
return result;
}