Hi, 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.
A:
protected internal override void Render(HtmlTextWriter writer)
{
/// use HtmlTextWriter to customize your output
}
Chris Ballance
2009-02-06 20:35:51
How would I use that to get the RAW html after the data has been binded to the grid?
Oliver S
2009-02-06 20:36:41
Ok, create a writer object and pass it to this function:RenderContents(writer); then the contents of the writer has the output you want.
Chris Ballance
2009-02-06 20:41:38
+1
A:
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?
BC
2009-02-06 20:38:03
Also see this link: http://msdn.microsoft.com/en-us/magazine/cc163543.aspx
Joel Coehoorn
2009-02-06 20:45:10
+6
A:
var outputBuffer = new StringBuilder();
using (var writer = new HtmlTextWriter(new StringWriter(outputBuffer)))
{
yourDataGrid.RenderControl(writer);
}
outputBuffer.ToString();
bdukes
2009-02-06 20:40:46
+1
A:
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);
}
M4N
2009-02-06 20:44:50