多重编辑/保存网格(hiddenfield + javascript)
我有一个包含 10 行的 gridview,其中 1 列是可以编辑的组合框。当我单击“编辑”按钮时,所有 10 行都变得可编辑,并且我想跟踪我更改了哪些行,这样如果仅对其中 2 行进行了更改,我就不会将所有 10 行保存到数据库中他们。到目前为止我的想法:
在网格中创建一个额外的隐藏列(就像一个告诉该行已编辑的复选框) 在组合框上的 SelectedIndexChanged 上,我将找到一个脚本,该脚本告诉我当前正在编辑的网格行,并在该行的隐藏列中设置复选标记
然后,当我按“保存”时,我可以遍历网格线并查看哪些有复选标记,然后将这些行保存到数据库
Javascript 不是我的强项,因此任何帮助/提示将不胜感激,或者完全不同的解决方案也可以工作:)
I got a gridview which contains 10 rows where 1 of the columns is a combobox that can be edited. When I click on an "edit" button, all of the 10 rows becomes editable and I want to keep track of which rows I have changed so that I dont save all 10 rows to the DB if there has only been made changes to 2 of them. My toughts so far:
Make an extra hidden column in the grid (like a checkbox that tells that the row is edited)
On SelectedIndexChanged on the combobox im going to find a script that tells me the grid-row im currently editing and sets the checkmark in the hidden column for that row
Then when i press "Save" I can run through the lines of the grid and see which ones has the checkmark and then save those rows to the DB
Javascript is not my strong side so any help/tips would be appreciated, or a completely different solution would work too :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的解决方案:
添加了一个
在网格的 ItemTemplate
然后在 RowDataBound 上的网格中我找到了隐藏字段
Dim hdnField As HtmlInputHidden = DirectCast(e.Row.FindControl("hdnIsChanged"), HtmlInputHidden)
和 dropdownlist
Dim ddlTest As DropDownList = CType(e.Row.FindControl("ddlTest"), DropDownList)
ddlTest.Attributes.Add("onChange", "Test('" + hdnField.ClientID + "');")
最后,我可以遍历网格的行并查看哪些行已更改:
My solution:
Added a
<input type="hidden" id="hdnIsChanged" runat="server" />
in the ItemTemplate of the grid
Then in the grid on RowDataBound i found the hiddenField
Dim hdnField As HtmlInputHidden = DirectCast(e.Row.FindControl("hdnIsChanged"), HtmlInputHidden)
and dropdownlist
Dim ddlTest As DropDownList = CType(e.Row.FindControl("ddlTest"), DropDownList)
ddlTest.Attributes.Add("onChange", "Test('" + hdnField.ClientID + "');")
Finally I could run through the rows of the grid and see which ones had changed: