1

我有这个包含网格的多视图控件:

<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 返回。

4

1 回答 1

0

当您直接引用 RadGrid1 时,您的功能似乎中断了。由于它被埋在多视图中,请首先找到活动视图并向下钻取到网格。试试这个

  RadGrid  RadGrid1=(RadGrid)MultiView1.Views(1).FindControl("RadGrid1");
  RadGrid1.RenderControl(oHtmlTextWriter);

这样您就可以确保正确定位 RadGrid1 及其内容。

于 2013-07-26T13:27:52.763 回答