我有这个包含网格的多视图控件:
<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 返回。