public List<ComboBoxD> GetEdades() { List<ComboBoxD> lista = new List<ComboBoxD>(); DateTime now = DateTime.Now; ComboBoxD item = new ComboBoxD(); item.ID = now.Year.ToString(); item.Descripcion = now.Year.ToString(); lista.Add(item); for (int i = 1; i < 100; i++) { DateTime nowF = DateTime.Now; ComboBoxD itemF = new ComboBoxD(); itemF.ID = nowF.AddYears(-(i)).Year.ToString(); itemF.Descripcion = nowF.AddYears(-(i)).Year.ToString(); lista.Add(itemF); } return lista; }
private List<ComboBoxD> ParseDataTableComboBox(System.Data.DataTable dataTable) { List<ComboBoxD> list = new List<ComboBoxD>(); for(int i = 0; i< dataTable.Rows.Count ; i ++) { DataRow row = dataTable.Rows[i]; var values = row.ItemArray; ComboBoxD cbo = new ComboBoxD(); if (values.Count() == 1) { cbo.ID = i.ToString() ; cbo.Descripcion = values[0].ToString(); } else { cbo.ID = values[0].ToString(); cbo.Descripcion = values[1].ToString(); } list.Add(cbo); } return list; }