有没有一种方法可以编程访问ReorderList (ASP.NET AJAX控件工具包)的DragHandleTemplate?特别是在ReorderList的ItemDataBound期间,为了在每个项目级别更改其外观?
发布于 2009-02-02 10:12:52
不幸的是,没有办法从ReorderListItem获得拖拽支架。相反,您可以在DragHandleTemplate中创建一个服务器控件(例如PlaceHolder),然后在ItemDataBound事件处理程序中找到它:
在aspx文件中:
<DragHandleTemplate>
<div class="dragHandle">
<asp:Label ID="lblDragHandle" runat="server" />
</div>
</DragHandleTemplate>在aspx.cs文件中:
protected void ReorderList1_ItemDataBound(object sender, AjaxControlToolkit.ReorderListItemEventArgs e)
{
Label lblDragHandle = (Label)FindControlRecursive(e.Item, "lblDragHandle");
lblDragHandle.Text = e.Item.ItemIndex.ToString();
}
private Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
{
return root;
}
foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
{
return t;
}
}
return null;
}我从杰夫的博客中复制了FindControlRecursive方法。
发布于 2011-04-30 01:40:02
你也可以在LINQ中表达FindControlRecursive:
private Control FindControlRecursive(Control root, string id)
{
return root.ID == id
? root
: (root.Controls.Cast<Control>().Select(c => FindControlRecursive(c, id)))
.FirstOrDefault(t => t != null);
}发布于 2009-01-29 15:34:00
您不能在服务器上以编程方式访问DragHandleTemplate选择器,但是如果您创建具有唯一ID(每行)的周围元素,您应该能够使用CSS-或Javascript来仅更改某些项。
https://stackoverflow.com/questions/299433
复制相似问题