Reputation: 611
I was wondering if there was a way to some how get the HTML output of a DataGrid. I want the raw HTML after the data has been bound to the grid. Is there some sort of overload for the render method I can use to accomplish this? Thanks.
Upvotes: 2
Views: 1349
Reputation: 34337
protected internal override void Render(HtmlTextWriter writer)
{
/// use HtmlTextWriter to customize your output
}
Upvotes: -1
Reputation: 96551
You could use this approach in your class (derived from DataGrid):
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
base.Render(hw);
string html = ProcessHtml(sw.ToString());
writer.Writer(html);
}
Upvotes: 1
Reputation: 155915
var outputBuffer = new StringBuilder();
using (var writer = new HtmlTextWriter(new StringWriter(outputBuffer)))
{
yourDataGrid.RenderControl(writer);
}
outputBuffer.ToString();
Upvotes: 7
Reputation: 24908
Even if you did override the Render method and call the base Render method, the HTML would be in the stream.
Perhaps the Control Adapter architecture may help whatever you're trying to accomplish?
Upvotes: 1