Here is what I came up with, it seems to work well, but I was wondering if this is the best way.
First, I created an object that looks like my results form my query,
public class MyTestObj
{
public string Value_CD { get; set; }
public string Text_NA { get; set; }
}
Then I create an ILIST and populate it with datatable strings
IList<MyTestObj> MyList = new List<MyTestObj>();
foreach (DataRow mydataRow in myDataTable.Rows)
{
MyList.Add(new MyTestObj()
{
Value_CD = mydataRow["Value"].ToString().Trim(),
Text_NA = mydataRow["Text"].ToString().Trim()
});
}
return new SelectList(MyList, "Value_CD", "Text_NA");
Any comments on this approach?
source
share