我已经被困了两天多,我到处寻找解决方案但没有结果,为什么当我尝试将 Grid 呈现为 html 时它返回空值?这是我的代码:
<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>
C#:
private void convertRadGridTohtml()
{
StringBuilder SB = new StringBuilder();
StringWriter SW3 = new StringWriter(SB);
HtmlTextWriter htmlTW = new HtmlTextWriter(SW3);
RadGrid RadGrid1 = (RadGrid)MultiView1.Views[1].FindControl("RadGrid1");
RadGrid1.RenderControl(htmlTW);
StringWriter oStringWriter = new StringWriter();
HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
RadGrid1.RenderControl(oHtmlTextWriter);
string html = oHtmlTextWriter.InnerWriter.ToString();
// toput.InnerHtml = html;
}
protected void save_click(object sender, EventArgs e)
{
convertRadGridTohtml();
}
protected void Page_Load(object sender, EventArgs e)
{
RadGrid1.DataSource= CreateTable();
RadGrid1.DataBind();
}