【问题标题】:Gridview rows unaccessible at server sideGridview 行在服务器端无法访问
【发布时间】:2017-04-07 15:23:02
【问题描述】:

我使用了asp:GridViewClientIDMode="Static" 和ID="GridView2",它显示了一些特定的结果,比如单击按钮时的帐户详细信息。

首先我对网格进行数据绑定,除了回发延迟和整个页面重绘之外,其他一切都很好。

(GridView2.DataSource = datatable.DefaultView;
 GridView2.DataBind();)

现在我正在使用 Ajax 来更新这个网格(我在 Ajax 函数中创建网格的 html 并像这样在 Grid html 上覆盖它

$('#GridView2').html(html.join(''))

),它正在正确绘制,但现在我无法在服务器端访问它的行。

for (int rows = 0; rows < mayDataGrid.Rows.Count; rows++)//.Rows.Count is always 0 but in html it is there.

【问题讨论】:

  • 你应该将 GridView 包裹在 UpdatePanel 中以 ajaxify 网格而不是手动在 dom 元素中注入 html

标签: asp.net


【解决方案1】:

当 gridview 呈现时,它也会在 ViewState 中呈现其 ControlState,当页面回发网格的当前状态(行更改,如添加/编辑/删除等)时,此 ControlState 在服务器上检测到,而不是 html 标记(您正在更改) .

因此,对 html 的任何更改都不会在服务器端生效。

【讨论】:

    猜你喜欢
    • 2014-07-20
    • 2013-12-27
    • 2021-01-25
    • 1970-01-01
    • 2020-09-19
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 1970-01-01
    相关资源
    最近更新 更多