Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

Actually I have 4 search bar in search engine location, skills, functional area and industry and this search leads to datalist with some detail with posted date.

now i have to dropdown with 60 days and 30days fresh data filter from that datalist.

so i used this code

 if (ddfreshness.SelectedItem.ToString() == "Any")
        {
            BindDataList();
        }
        else if (ddfreshness.SelectedItem.ToString() == "30 Days")
        {
            foreach (DataListItem dli in DataList1.Items)
            {
//fetching posted date from datalist
                Label l45 = (Label)dli.FindControl("lblprloc2");

                DateTime now = DateTime.Today;
                TimeSpan ts = now - Convert.ToDateTime(l45.Text);
                // Difference in days.

                int differenceInDays = ts.Days;
                string date = Convert.ToString(differenceInDays) + " Days";
               
                if (differenceInDays <= 30)
                {
                   
//bind fuction for the data to same datalist
                    BindDataList();
                    
                }
            }
        }



Collection was modified; enumeration operation may not execute

plz help me for this code.
Posted
Updated 14-Dec-13 17:15pm
v2
Comments
OriginalGriff 10-Dec-13 11:45am    
"it gives some enumeration error"
This is not a helpful error message.
Please copy and paste the exact error message you get, tell us when you get it, and which line of your code it is referring to.
Use the "Improve question" widget to edit your question and provide better information.
aarohi verma 26-Dec-13 9:45am    
hi,
due to other coding issue I cant solve this issue and also now my email account is not working,(cant open it, dont know why) ,can you suggest me how can i solve this code issue?
OriginalGriff 26-Dec-13 11:19am    
As I said 11 days ago:
"Move the BindDataList call outside the loop."
aarohi verma 30-Dec-13 0:27am    
I do this as you said but if i move this outside then only lastdata is came out as result.not all.
joginder-banger 15-Dec-13 0:35am    
I think first of all you make a store procedure, I have a complete query with front end coding, if you really need this, I can send your email id,share you personal email id.

1 solution

You cannot rebind the day a list within a foreach loop on the list of items in the datalist!
You can't do that with any collection that is being used with a foreach - it changes the number or order of the items that the loop is trying to iterate through.

Move the BindDataList call outside the loop.
 
Share this answer
 

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