
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; }
<telerik:GridTemplateColumn DataField="Comments" AllowFiltering="false" FilterControlAltText="Filter Comments column" HeaderText="Comments" SortExpression="Comments" UniqueName="Comments">
<EditItemTemplate>
<asp:TextBox ID="txtComments" runat="server" Text='<%# Bind("Comments")%>' TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvComments" ControlToValidate="txtComments" Display="Dynamic" runat="server" ErrorMessage="Please enter a reason for changing this budget item."></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="CommentsLabel" runat="server" Text='<%# Eval("Comments") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>