Hi all.
Got a stupid problem here and was hoping someone could point at me, laugh, and tell me what i've done wrong. The problem is a simple one. I need to set the Places Remaining column to align right in the following code:
DataTable myDataTable = new DataTable();
DataRow myDataRow;
TrainDB mySP = new TrainDB();
SqlDataReader myReader = null;
myDataTable.Columns.Add(new DataColumn("Date", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Title", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Duration\n(Days)", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Start", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Finish", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Places Remaining", typeof(int)));
while (myReader.Read())
{
try
{
if (Convert.ToInt32(myReader.GetValue(5)) - Convert.ToInt32(myReader.GetValue(6)) > 0)
{
//Create a new data row in the data table
myDataRow = myDataTable.NewRow();
myDataRow[0] = DateTime.Parse(myReader.GetValue(0).ToString()).ToShortDateString();
myDataRow[1] = myReader.GetValue(1);
myDataRow[2] = myReader.GetValue(2);
myDataRow[3] = DateTime.Parse(myReader.GetValue(3).ToString()).ToShortTimeString();
myDataRow[4] = DateTime.Parse(myReader.GetValue(4).ToString()).ToShortTimeString();
myDataRow[5] = Convert.ToInt32(myReader.GetValue(5)) - Convert.ToInt32(myReader.GetValue(6));
myDataTable.Rows.Add(myDataRow);
}
}
catch{
}
}
myReader.Close();
DataView myDataView = new DataView(myDataTable);
myDataGrid.DataSource = myDataView;
myDataGrid.AllowPaging = true;
myDataGrid.PagerStyle.Mode = PagerMode.NumericPages;
myDataGrid.PageSize = 15;
myDataGrid.AllowSorting=false;
myDataGrid.HeaderStyle.CssClass="thstyle";
myDataGrid.PagerStyle.CssClass="pgstyle";
myDataGrid.PagerStyle.NextPageText="Next Page";
myDataGrid.PagerStyle.PrevPageText="Previous Page";
myDataGrid.AlternatingItemStyle.CssClass="gridalt";
myDataGrid.CssClass="gridstyle";
myDataGrid.DataBind();
lblPage.CssClass="currentpage";
lblPage.Text = "Page No: " + (myDataGrid.CurrentPageIndex + 1);
Session["Source"] = myDataTable;
I've done the myDataGrid.Column[5].HorizontalAlignment but the problem is the column collection is zero when i try and do it... what am i missing?
cheers all
Rob
Got a stupid problem here and was hoping someone could point at me, laugh, and tell me what i've done wrong. The problem is a simple one. I need to set the Places Remaining column to align right in the following code:
DataTable myDataTable = new DataTable();
DataRow myDataRow;
TrainDB mySP = new TrainDB();
SqlDataReader myReader = null;
myDataTable.Columns.Add(new DataColumn("Date", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Title", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Duration\n(Days)", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Start", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Finish", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Places Remaining", typeof(int)));
while (myReader.Read())
{
try
{
if (Convert.ToInt32(myReader.GetValue(5)) - Convert.ToInt32(myReader.GetValue(6)) > 0)
{
//Create a new data row in the data table
myDataRow = myDataTable.NewRow();
myDataRow[0] = DateTime.Parse(myReader.GetValue(0).ToString()).ToShortDateString();
myDataRow[1] = myReader.GetValue(1);
myDataRow[2] = myReader.GetValue(2);
myDataRow[3] = DateTime.Parse(myReader.GetValue(3).ToString()).ToShortTimeString();
myDataRow[4] = DateTime.Parse(myReader.GetValue(4).ToString()).ToShortTimeString();
myDataRow[5] = Convert.ToInt32(myReader.GetValue(5)) - Convert.ToInt32(myReader.GetValue(6));
myDataTable.Rows.Add(myDataRow);
}
}
catch{
}
}
myReader.Close();
DataView myDataView = new DataView(myDataTable);
myDataGrid.DataSource = myDataView;
myDataGrid.AllowPaging = true;
myDataGrid.PagerStyle.Mode = PagerMode.NumericPages;
myDataGrid.PageSize = 15;
myDataGrid.AllowSorting=false;
myDataGrid.HeaderStyle.CssClass="thstyle";
myDataGrid.PagerStyle.CssClass="pgstyle";
myDataGrid.PagerStyle.NextPageText="Next Page";
myDataGrid.PagerStyle.PrevPageText="Previous Page";
myDataGrid.AlternatingItemStyle.CssClass="gridalt";
myDataGrid.CssClass="gridstyle";
myDataGrid.DataBind();
lblPage.CssClass="currentpage";
lblPage.Text = "Page No: " + (myDataGrid.CurrentPageIndex + 1);
Session["Source"] = myDataTable;
I've done the myDataGrid.Column[5].HorizontalAlignment but the problem is the column collection is zero when i try and do it... what am i missing?
cheers all
Rob