使用中继器排序后返回列表
我有一个列表进入中继器,使用 jquery sortable() 进行排序,然后需要将排序后的列表放入会话变量中。我似乎无法弄清楚如何将排序后的值放回到列表中。
Html 代码:
<div>
<asp:Repeater ID="LstSortable" runat="server">
<HeaderTemplate>
<ul id="sortable">
</HeaderTemplate>
<ItemTemplate>
<li>
<%# Container.DataItem %>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
页面加载:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'create test array
Dim order As New List(Of String)
order.Add("Item1")
order.Add("Item2")
order.Add("Item3")
order.Add("Item4")
'testing repeater
LstSortable.DataSource = order
LstSortable.DataBind()
End Sub
按下按钮将排序列表放入会话变量中:
这是我正在使用的代码,它当前不起作用:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim orderBy As New List(Of String)
Dim count As Integer
For count = 0 To LstSortable.Items.Count - 1 Step count + 1
Dim chk As ListItem = CType(LstSortable.Items(count).FindControl(LstSortable.ID), ListItem)
Next
Session("OrderBy") = orderBy
End Sub
感谢任何帮助。谢谢。
这是使用vb.net。
I have a list going into a repeater, sorting with jquery sortable(), and then need to put the sorted list into a session variable. I cannot seem to figure out how to get the sorted values back into a list.
Html code:
<div>
<asp:Repeater ID="LstSortable" runat="server">
<HeaderTemplate>
<ul id="sortable">
</HeaderTemplate>
<ItemTemplate>
<li>
<%# Container.DataItem %>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
page load:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'create test array
Dim order As New List(Of String)
order.Add("Item1")
order.Add("Item2")
order.Add("Item3")
order.Add("Item4")
'testing repeater
LstSortable.DataSource = order
LstSortable.DataBind()
End Sub
button press to put sorted list into session variable:
This is the code I am playing with, it currently does not work:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim orderBy As New List(Of String)
Dim count As Integer
For count = 0 To LstSortable.Items.Count - 1 Step count + 1
Dim chk As ListItem = CType(LstSortable.Items(count).FindControl(LstSortable.ID), ListItem)
Next
Session("OrderBy") = orderBy
End Sub
Any help is appreciated. Thanks.
This is using vb.net.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用 jquery 创建 li 元素数组,然后使用 ajax 调用将它们传递到 Web 服务来修复此问题。
我必须在 Web 服务中启用会话:
然后我将数组解析为字符串并放入会话变量中。
jquery:
网络服务:
I fixed this by creating an array of li elements using jquery and then passing them to a webservice using an ajax call.
I had to enable sessions in the web service:
Then I parsed the array into a string and placed in the session variable.
jquery:
web service: