C#中的datalist天搜索问题 [英] datalist days search problem in C#

查看:69
本文介绍了C#中的datalist天搜索问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



实际上我在搜索引擎的位置,技能,功能区和行业中都有4个搜索栏,这个搜索引出了数据列表,其中包含一些详细信息约会。



现在我必须从该数据列表中下载60天和30天的新数据过滤器。



所以我用这个代码



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.

推荐答案

你不能重新绑定当天数据列表中项目列表中的foreach循环中的列表!

对于与foreach一起使用的任何集合,您不能这样做 - 它会更改项目的数量或顺序循环试图迭代。



在循环外移动BindDataList调用。
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.


这篇关于C#中的datalist天搜索问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆