如何从代码隐藏的页面方法更新 GridView?

发布于 2024-07-06 16:49:06 字数 221 浏览 10 评论 0原文

如何通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘过的浮云 2024-07-13 16:49:06

您可以动态/编程方式构建 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文