您好,
我一个ListBox绑定到SqlDataSource。我有2场中的SqlDataSource,所有权和display_order。
当页面被加载,加载列表框的标题字段为了display_order(选择称号display_order表顺序)。
我有2个按钮控件旁边的列表框(上下),使用户可以移动选定的项目和下降。
当用户重新排列的ListItem的订单,我想打电话给SqlDataSource控件的update()和填充ListBox的索引值display_order。我应该怎样做呢?请帮助。
感谢
sameera
从OP的答案]
没有,我没有ListBox的索引没有在我的数据库字段是。用随机数填充display_order领域。我会复制我的代码如下:
{C}
Imports System.Web.UI.WebControls
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub down_Click(sender As Object, e As System.EventArgs) Handles down.Click
'Make sure our item is not the last one on the list.
If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then
'Insert places items above the index you supply, since we want
'to move it down the list we have to do + 2
Dim I = ListBox1.SelectedIndex + 2
ListBox1.Items.Insert(I, ListBox1.SelectedItem)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
ListBox1.SelectedIndex = I - 1
End If
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
For Each ListItem In ListBox1.Items
'this is not working....
sdssiteorder.UpdateParameters("SITE_MAP_DISPLAY_ORDER").DefaultValue = ListBox1.Items.IndexOf(ListItem)
sdssiteorder.Update()
Next
End Sub
End Class