我有这个包含网格的多视图控件:
<asp:MultiView ID="MultiView1" ActiveViewIndex="0" runat="server" >
<asp:View ID="View1" runat="server" >
<telerik:RadGrid ID="RadGrid1" runat="server" RegisterWithScriptManager="false" AutoGenerateColumns="false" >
<MasterTableView>
<Columns>
<telerik:GridBoundColumn HeaderText="ID" DataField="ID"></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Name" DataField="NAME"></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="LastName" DataField="LASTNAME"></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Description" DataField="DESCRIPTION"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:Button ID="Navigate" runat="server" OnClick="Navigate_Click" Text="Next" />
</asp:View>
<asp:View ID="View2" runat="server" >
Save your changes
<asp:Button ID="save" runat="server" OnClick="save_click" Text="Save " />
</asp:View>
</asp:MultiView>
服务器代码:
private void convertRadGridTohtml()
{
StringBuilder SB = new StringBuilder();
StringWriter SW3 = new StringWriter(SB);
HtmlTextWriter htmlTW = new HtmlTextWriter(SW3);
RadGrid1.RenderControl(htmlTW);
StringWriter oStringWriter = new StringWriter();
HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
RadGrid1.RenderControl(oHtmlTextWriter);
string html = oHtmlTextWriter.InnerWriter.ToString();
// toput.InnerHtml = html;
}
当网格放置在多视图内部时,该函数总是返回一个空字符串,但是当放置在多视图之外时,html对象工作正常,它将网格作为html返回。
答案 0 :(得分:0)
当您直接引用RadGrid1时,您的函数似乎会中断。因为它隐藏在多视图中,首先找到活动视图并向下钻取到网格。试试这个
RadGrid RadGrid1=(RadGrid)MultiView1.Views(1).FindControl("RadGrid1");
RadGrid1.RenderControl(oHtmlTextWriter);
通过这种方式,您可以确保正确找到RadGrid1及其内容。