Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ();
            }
Posted
Updated 13-Feb-18 1:42am

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.
 
Share this answer
 
Comments
Member 13174280 14-Feb-18 4:18am    
I have modified and executed the code (for db MySql) of the link, but only responds to the click on an Item of the DataList.
CHill60 14-Feb-18 7:08am    
"only responds to the click on an item of the DataList" ... the code responds to a click of a button. Instead of adding (and clicking) a button put that code into your timer event
Try this:

if (DataList1.Items.Count > 0)
{
    Control ctrl = DataList1.Items[idxImage];
    if (ctrl != null)
    {
        SetFocus(ctrl);
    }
}
 
Share this answer
 
v2
Comments
Member 13174280 14-Feb-18 4:24am    
This solution is better than mine, I still can't move the focus from one item to the next.
I think we can simulate the click on ImageButton control

protected void Timer1_Tick(object sender, EventArgs e)
{
//simulate clck on ImageButton to enable event
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900