你好朋友我想创建自定义通用列表我的代码如下:
public class Dates
{
string _FromDate;
string _ToDate;
public string FromDate
{
get { return _FromDate; }
set { _FromDate = value; }
}
public string ToDate
{
get { return _ToDate; }
set { _ToDate = value; }
}
}
protected void btnsearch_Click(object sender, EventArgs e)
{
DateTime start = new DateTime(2013,1,5);
DateTime end = new DateTime(2013,2,2);
string dayName = drpday.SelectedItem.ToString().ToLower();
Dates dt = new Dates();
List<Dates> list = new List<Dates>();
int i = 0;
for (DateTime runDate = start; runDate <= end; runDate = runDate.AddDays(1))
{
if (runDate.DayOfWeek.ToString().ToLower() == dayName)
{
dt.FromDate = runDate.ToShortDateString();
dt.ToDate = (runDate.AddDays(double.Parse(hd_tourdays.Value)).ToShortDateString());
list.Insert(i++,dt);
}
}
grd_TourDates.DataSource = list;
grd_TourDates.DataBind();
}
在我的结果列表中,它只显示循环中添加的最后一项,请帮助解决问题..