在客户端上的 ASP.net 列表框中重新排序项目,然后在服务器上识别它
我有一个管理页面,其中有一个充满值的列表框。用户还可以通过一些 jquery 更改值的顺序,理论上我们将保存该顺序,并且它将更改其他一些异国语言环境中列表框中的显示顺序。
jquery 工作正常。当用户保存时,我使用此代码来处理列表框:
index = 0;
foreach (ListItem item in lstProspectStatus.Items)
{
//Save that particular item's data, using index as the value for the
//display sequence field.
index++;
}
问题是,Items 集合返回填充控件时项目的顺序。客户端订单更改将被忽略。
对我来说解决这个问题的最佳方法是什么?
I've got an administrative page with a listbox filled with values. A user can also change the order of the values via some jquery, and in theory we'll save that order and it will change the order of display in a listbox in some other, exotic, locale.
The jquery works fine. When the user saves I use this code to process the listbox:
index = 0;
foreach (ListItem item in lstProspectStatus.Items)
{
//Save that particular item's data, using index as the value for the
//display sequence field.
index++;
}
The problem is, the Items collection is returning the order the items where in when the control was populated. The client-side order change is ignored.
What is the best way for me to approach this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会将新订单存储到隐藏字段中,然后在服务器端读取该字段。
您遇到的问题是,当系统在回发周期期间重建下拉列表时,ASP.NET 会重置这些元素的顺序。
I would stash the new order into a hidden field, and then read from that on the server side.
The problem you're getting is that the sequence of those elements is getting reset by ASP.NET when the system rebuilds the dropdownlist during the postback cycle.