ok, here it is, I've truncated and pseudo coded it a bit but the important parts is there I'm not creating in the oninit, this is true all though i have tried it, I'll try again while you view this. thanks for taking a look.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// set page up populate some drop downs etc.
}
BindGrid(); -- this just gets a dataset based on the dropdowns mentioned above and then calls the DataTableModel() the dataset returns fine.
}
public void DataTableModel()
{
if (ph.Controls.Count < 1)
{
tblApts = new Table();
tblApts.BackColor = Color.White;
tblApts.Width = Unit.Percentage(100);
tblApts.CellSpacing = 0;
tblApts.ID = "tblApts";
ph.Controls.Add(tblApts);
}
if (tblApts.Rows.Count > 1)
tblApts.Rows.Clear();
bool alternate = false;
if (source.Rows.Count <= 0)
return;
DateTime date = (DateTime)source.Rows[0][0];
TableRow header = new TableRow();
header.BackColor = Color.FromName("#bbbbbb");
CreateHeaderRow(header);
tblApts.Rows.Add(header);
for (int rowIndex = 0; rowIndex < source.Rows.Count; rowIndex++)
{
TableRow tr = new TableRow();
if (alternate)
{
tr.BackColor = Color.WhiteSmoke;
alternate = false;
}
else
alternate = true;
DataRow dr = source.Rows[rowIndex];
for (int cellIndex = 1; cellIndex < dr.ItemArray.Length; cellIndex++)
{
TableCell td = new TableCell();
if (cellIndex > 1)
{
if (rowIndex == 0)
CreateCell(td, dr[cellIndex].ToString(), "", source.Rows[rowIndex + 1][cellIndex].ToString(), "xx~" + dr[1].ToString() + "~" + DateFunctions.GetDayForNumber(cellIndex - 1, Co.FirstDayOfWeek), !alternate);
else if (rowIndex == source.Rows.Count - 1)
CreateCell(td, dr[cellIndex].ToString(), source.Rows[rowIndex - 1][cellIndex].ToString(), "", "xx~" + dr[1].ToString() + "~" + DateFunctions.GetDayForNumber(cellIndex - 1, Co.FirstDayOfWeek), !alternate);
else
CreateCell(td, dr[cellIndex].ToString(), source.Rows[rowIndex - 1][cellIndex].ToString(), source.Rows[rowIndex + 1][cellIndex].ToString(), "xx~" + dr[1].ToString() + "~" + DateFunctions.GetDayForNumber(cellIndex - 1, Co.FirstDayOfWeek), !alternate);
}
else
{
Label time = new Label();
time.Text = dr[1].ToString();
time.CssClass = "Form_Label";
td.Controls.Add(time);
td.Attributes.Add("Style", "border:ridge 2px");
}
if (td.Controls.Count > 0)
tr.Cells.Add(td);
}
// add second time column at the end
TableCell tdEnd = new TableCell();
Label timeEnd = new Label();
timeEnd.Text = dr[1].ToString();
timeEnd.CssClass = "Form_Label";
tdEnd.Controls.Add(timeEnd);
tdEnd.Attributes.Add("Style", "border:ridge 2px");
tr.Cells.Add(tdEnd);
tblApts.Rows.Add(tr);
}
}
void CreateCell(TableCell td, string item, string previous, string next, string arg, bool alt)
{
LinkButton lb = new LinkButton();
lb.CssClass = "Form_Grid";
lb.Width = Unit.Pixel(80);
lb.Height = Unit.Percentage(100);
lb.Click += new EventHandler(Apt_Click);
lb.CommandArgument = arg;
string style = "border-left:ridge 2px; border-right:ridge 2px;";
int aptNum = 0;
string trName;
string type;
switch (item)
{
case "Full":
style += "background-color:gray; border-top:ridge 2px; border-bottom:ridge 2px; ";
break;
case "Not Full":
style += "background-color:ButtonFace; border-top:ridge 2px; border-bottom:ridge 2px; ";
break;
case "Empty":
lb.Text = "EmptyEmpty";
style += "border-top:ridge 2px; border-bottom:ridge 2px; ";
if (alt)
lb.ForeColor = System.Drawing.Color.WhiteSmoke;
else
lb.ForeColor = System.Drawing.Color.White;
break;
default:
aptNum = Int32.Parse(item.Substring(0, item.IndexOf("~")));
trName = item.Substring(item.IndexOf("~") + 1, item.LastIndexOf("~") - 3);
type = item.Substring(item.LastIndexOf("~") + 1);
lb.CommandArgument = item + "~" + arg.Substring(arg.LastIndexOf("~") - 3); ;
if (AptType.GetIfMultipleByDescription(type, ((ASP.masterpages_masterpage_master)Page.Master).CoId))
lb.Text = trName;
else
lb.Text = GetClientList(aptNum);
lb.Font.Underline = false;
lb.ToolTip = "Client(s): " + GetClientList(aptNum);
style += "border-top:ridge 2px; border-bottom:ridge 2px; background-color:Green; ";
string filter = "apt_id = " + aptNum;
DataRow[] dr = DS.Tables[2].Select(filter);
td.RowSpan = Int32.Parse(dr[0][1].ToString());
td.VerticalAlign = VerticalAlign.Top;
td.HorizontalAlign = HorizontalAlign.Center;
if (previous.Contains("~") && previous.Substring(0, previous.IndexOf("~")) == aptNum.ToString())
{
td = null;
return;
}
else
style += " border-top:ridge 2px; ";
if (!next.Contains("~") || next.Substring(0, next.IndexOf("~")) != aptNum.ToString())
style += " border-bottom:ridge 2px; ";
break;
}
td.Controls.Add(lb);
td.Attributes.Add("Style", style);
}