以一个实例说明
//录入年份绑定
[csharp] view plain
- string str1=str.Remove(0,i);
- string str1=str.SubString(i);
- public void YearList(FineUIPro.DropDownList ddlYear)
- public void YearList(FineUIPro.DropDownList ddlYear)
- {
- //年份从15年到当前年//起止年份
- int yearStart = 2015;
- int yearEnd = DateTime.Now.Year.ToString().ToInt();//当前年份
- //往Datatable中添加新行的步骤主要有
// 第一,声明一个Datatable;
// 第二,向Datatable中添加列;
// 第三,向Datatable中添加行
//①声明一个dataTable
DataTable Year = new DataTable();
//②添加列
Year.Columns.Add("Value",typeof(int));
Year.Columns.Add("Name",typeof(string));//③添加行
for (int i = 0; i< yearEnd- yearStart+1; i++)
{
DataRow row = Year.NewRow();
int value = yearStart + i;
string name= (yearStart + i).ToString();object[] objs = { value, name};
//dr.ItemArray = objs;
row["Value"] = objs[0];
row["Name"] = objs[1];
Year.Rows.Add(row.ItemArray);
}
ddlYear.DataSource = Year;
ddlYear.DataTextField = "Name";
ddlYear.DataValueField = "Value";
ddlYear.DataBind();
}
[csharp]
原文地址:https://www.cnblogs.com/dyhao/p/9343885.html
时间: 2024-10-09 17:39:51