在asp.net ajax工具包控件中我正在使用reorderlist。
当我第一次重新排序时,它工作正常,但事实并非如此。
以下是我的代码..
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ReorderList ID="rlItemList" DragHandleAlignment="Left" PostBackOnReorder="false"
DataKeyField="VentureCategoryID" runat="server" SortOrderField="DisplayOrder"
OnItemReorder="rlItemList_ItemReorder" AllowReorder="true" ClientIDMode="AutoID">
<DragHandleTemplate>
<div class="dragHandle">
</div>
</DragHandleTemplate>
<ItemTemplate>
<asp:Label ID="lblVentureCategoryID" runat="server" Visible="false" Text='<%#Eval("VentureCategoryID") %>' />
<asp:Label ID="lblCategoryName" runat="server" Text='<%#Eval("CategoryName") %>' />
<asp:Label ID="lblIsActive" runat="server" Text='<%#Eval("IsActive") %>' />
<asp:Label ID="lblDisplayOrder" runat="server" Visible="false" Text='<%#Eval("DisplayOrder") %>' />
</ItemTemplate>
<ReorderTemplate>
<asp:Panel ID="Panel2" runat="server" CssClass="reorderCue" />
</ReorderTemplate>
</asp:ReorderList>
后面的代码是......
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<VentureCategory> VenList = VentureCategory.GetAll();
rlItemList.DataSource = VenList;
rlItemList.DataBind();
}
}
protected void rlItemList_ItemReorder(object sender, ReorderListItemReorderEventArgs e)
{
var nId = e.NewIndex + 1;
var oId = e.OldIndex + 1;
List<VentureCategory> VenCatList = VentureCategory.GetAll();
//foreach (var item in VenCatList)
//{
// item.DisplayOrder = 9;
// VentureCategory.Update(item);
//}
int OldCategoryid = Convert.ToInt32(rlItemList.DataKeys[e.OldIndex].ToString());
int NewCategoryid = Convert.ToInt32(rlItemList.DataKeys[e.NewIndex].ToString());
var sortedList = VenCatList.OrderBy(sl => sl.DisplayOrder);
var Count = 1;
Label CatId = e.Item.FindControl("lblVentureCategoryID") as Label;
var newcatId = Convert.ToInt32(CatId.Text);
foreach (var item in sortedList)
{
if (oId > nId && Count >= nId && oId >= Count)
item.DisplayOrder = Count + 1;
else if (nId > oId && nId >= Count && Count >= oId)
item.DisplayOrder = Count - 1;
if (item.VentureCategoryID == newcatId)
item.DisplayOrder = nId;
VentureCategory.Update(item);
Count++;
}
}
谁能帮助我
提前致谢
答案 0 :(得分:0)
检查表是否具有相同的定义和相同的数据类型