是否有一个简单的调用webService方法重新绑定asp.Net GridView控件并返回其呈现的html,以便我可以刷新页面上包含gridview的区域?
我可以使用jQuery.Load但是在服务器端如何获取特定控件的渲染块?
由于
答案 0 :(得分:2)
您可以使用Gridview.RenderControl()方法。
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.
}
答案 1 :(得分:0)
你可以在网络方法中做这样的事情。
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();