G
Guest
I have a SQL Server table called "ClosedMonths" that contains two pertinent
fields:
Yearx Monthx
2000 1
2000 2
2000 3
I want to simply query this table and populate a WebControls listbox with
the contents, though in this format:
Jan 2000
Feb 2000
Mar 2000
So I wrote the following code:
DataSet dataSet = new DataSet();
dataSet.Tables.Add(BusObjects.Archiving.GetClosedMonths());
dataSet.Tables[0].Columns.Add("MonthDate");
foreach(DataRow row in dataSet.Tables[0].Rows)
{
row["MonthDate"] = Enum.GetName(typeof(MonthShort), row["Monthx"])
+ " " + row["Yearx"].ToString();
}
listBoxDates.DataSource = dataSet.Tables[0];
listBoxDates.DataTextField = "MonthDate";
listBoxDates.DataBind();
Where 'MonthShort' is a simple enumeration in which Jan = 1, Feb = 2, etc.
Anyhow, this code works fine but I'm wondering if there isn't a simpler way
to do it?
I also have a second question: Is there a way to change the alignment of the
contents of the ListBox to be something other than left-aligned?
fields:
Yearx Monthx
2000 1
2000 2
2000 3
I want to simply query this table and populate a WebControls listbox with
the contents, though in this format:
Jan 2000
Feb 2000
Mar 2000
So I wrote the following code:
DataSet dataSet = new DataSet();
dataSet.Tables.Add(BusObjects.Archiving.GetClosedMonths());
dataSet.Tables[0].Columns.Add("MonthDate");
foreach(DataRow row in dataSet.Tables[0].Rows)
{
row["MonthDate"] = Enum.GetName(typeof(MonthShort), row["Monthx"])
+ " " + row["Yearx"].ToString();
}
listBoxDates.DataSource = dataSet.Tables[0];
listBoxDates.DataTextField = "MonthDate";
listBoxDates.DataBind();
Where 'MonthShort' is a simple enumeration in which Jan = 1, Feb = 2, etc.
Anyhow, this code works fine but I'm wondering if there isn't a simpler way
to do it?
I also have a second question: Is there a way to change the alignment of the
contents of the ListBox to be something other than left-aligned?