如何从代码隐藏的页面方法更新 GridView?
如何通过 webmethod 更新 aspx 页面上的 Gridview?
这是我的代码。
[WebMethod]
public static string GetDate()
{
return DateTime.Now.ToString();
}
我无法使用“findcontrol”或“this”方法,因此我需要一些帮助。
How do I update a Gridview on a aspx page from a webmethod?
Here is my code.
[WebMethod]
public static string GetDate()
{
return DateTime.Now.ToString();
}
I can't use the "findcontrol" or the "this" methods so I need some help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以动态/编程方式构建 GridView 控件。 然后在 WebMethod 中,您可以调用 RenderControl() 方法来检索呈现的 GridView 控件的 HTML 内容。 从 WebMethod 返回该内容,并让回调 JavaScript 函数将 HTML 内容注入占位符元素的 innerHTML 属性中。
另一种选择是在客户端进行数据绑定。 因此,WebMethod 所要做的就是传回数据(不包括表示标记),例如以 JSON 类型的格式。 然后,您可以使用 javascript 模板 等内容来呈现包含数据的网格。 这种方法将 GridView 控件完全排除在外,但根据您的需要,它可能是一个可行的选择。
You can dynamically/programmatically build the GridView control. Then in your WebMethod, you can call RenderControl() method to retrieve the HTML content of the rendered GridView control. Return that content from the WebMethod and have the callback JavaScript function inject the HTML content into your placeholder element's innerHTML property.
Another option is to do your data binding on the client-side. So all the WebMethod has to do is pass back the data (excluding presentational markup), for example in a JSON-type format. Then you can use something like javascript templates to render the grid with data. This approach takes GridView control completely out of the picture, but depending on your needs, it may be a viable option.