手动更改数据列表中的项目 [英] Manually change an item in a datalist
本文介绍了手动更改数据列表中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:有10个项目的datalist,定期(定时器)我想改变Item [0],Item [1]等。
SetFocus(DataList1。Items [idxImage])不好,因为它总是返回到datalist的第一项。
我可以做一个循环来检查索引是否当前项目的等于计数器(idximage),但Focus()方法不会移动到项目。
我有什么试过:
Example: datalist with 10 items, at regular intervals (timer) I would like to change from Item[0], Item[1], etc.
SetFocus (DataList1. Items[idxImage]) is not good because it always returns to the first item of the datalist.
I can do a cycle to check if the index of the current item is equal to that of the counter (idximage), but the Focus () method does not move to the item.
What I have tried:
SetFocus (DataList1. Items[idxImage]) is not good because it always returns to the first item of the datalist.
foreach (DataListItem item in DataList1. Items)
{
if (item. ItemIndex == idxImage)
{
(item. FindControl ("ImageButton1") as ImageButton) Focus ();
}
推荐答案
听起来你正试图改变用计时器选择的项目?
阅读本CodeProject文章突出显示并选择数据列表中的项目 [ ^ ] - 您需要对其进行调整以处理您的计时器。
It sounds like you are trying to change which item is selected with a timer?
Have a read of this CodeProject article Highlighting and selecting an item in a DataList[^] - you will need to adapt it to deal with your timer.
试试这个:
Try this:
if (DataList1.Items.Count > 0)
{
Control ctrl = DataList1.Items[idxImage];
if (ctrl != null)
{
SetFocus(ctrl);
}
}
这篇关于手动更改数据列表中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文