Can I obtain the rendered html of a gridview via webService call?

前端 未结 2 1391
一整个雨季
一整个雨季 2021-01-28 23:23

Is there a simple of of calling a webService method that Rebinds an asp.Net GridView control and returns its rendered html so that I can refresh the region that contains the gri

相关标签:
2条回答
  • 2021-01-29 00:01

    You can use Gridview.RenderControl() method.

     System.IO.StringWriter stringWrite = new System.IO.StringWriter();    
     System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);    
     GridView2.RenderControl(htmlWrite);
    
    public override void VerifyRenderingInServerForm(Control control)
        {
           // Confirms that an HtmlForm control is rendered for the
           // specified ASP.NET server control at run time.
           // No code required here.
        }
    
    0 讨论(0)
  • 2021-01-29 00:03

    you can do something like this in the webmethod.

            GridView gv = new GridView();
            gv.AutoGenerateColumns = true;
            //Your Logic to fill dataset/datatable
            DataTable dt=new DataTable();
            dt.Columns.Add(new DataColumn("Index"));
            dt.Columns.Add(new DataColumn("Name"));
            for(int i=0;i<10;i++)
            {
                DataRow row=dt.NewRow();
                row["Index"]=i;
                row["Name"]="dummyData"+i.ToString();
                dt.Rows.Add(row);
            }
            //bind the gridview
            gv.DataSource = dt;
            gv.DataBind();
            //get the rendered HTML
            StringBuilder sb = new StringBuilder();
            StringWriter writer=new StringWriter(sb);
            HtmlTextWriter txt = new HtmlTextWriter(writer);
            gv.RenderControl(txt);
            return sb.ToString();
    
    0 讨论(0)
提交回复
热议问题