Ciao ragazzi,
sto realizzando un controllino per visualizzare i giorni con le ore nel dettaglio sottostante, tutto ok tranne un piccolo difetto...
In poche parole non riesco a troncare una cella che mi va in automatico su più righe
Se prendo il codice generato e lo butto su un file html tutto nella norma, invece lanciandolo da pagina aspx niente da fare
Vi posto il codice del tutto (ho tolto i commenti per non appensatire il post tanto è molto chiaro):
1. Per vedere il difetto provare a premere il tasto per indietraggiare di un'ora.
2. E' corretto realizzare i controlli in questo modo oppure ho intrapreso una strada sbagliata?
-- Header.css
-- Header.ascx
-- Header.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Header : System.Web.UI.UserControl
{
DateTime dtDay = DateTime.Today;
Int32 nHours = 24;
Int32 nStart = 0;
public Int32 Hours
{
get { return nHours; }
set { nHours = value; }
}
public Int32 Start
{
get { return nStart; }
set { nStart = value; }
}
public DateTime SelectedDate
{
get { return dtDay; }
set { dtDay = value; }
}
public void Next()
{
nStart += 1;
if (nStart > 23)
{
nStart = 0;
dtDay = dtDay.AddDays(1);
}
MakeControl();
}
public void Previous()
{
nStart -= 1;
if (nStart < 0)
{
nStart = 23;
dtDay = dtDay.AddDays(-1);
}
MakeControl();
}
public void NextDay()
{
dtDay = dtDay.AddDays(1);
MakeControl();
}
public void PreviousDay()
{
dtDay = dtDay.AddDays(-1);
MakeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
if (ViewState["SelectedDate"] != null)
dtDay = (DateTime)ViewState["SelectedDate"];
if (ViewState["Hours"] != null)
nHours = (Int32)ViewState["Hours"];
if (ViewState["Start"] != null)
nStart = (Int32)ViewState["Start"];
}
public void MakeControl()
{
Table tb1;
TableRow tr1, tr2;
TableCell tc;
Int32 z = 1;
tb1 = new Table();
tb1.CssClass = "tabella_hdr1";
tb1.CellPadding = 0;
tb1.CellSpacing = 0;
tr1 = new TableRow();
tr1.CssClass = "riga_hdr1";
tc = new TableCell();
tc.CssClass = "cella_hdr1";
tc.ColumnSpan = Math.Min(24,nHours) - nStart;
tc.Text = dtDay.ToString("dd MMMM yyyy");
tr1.Cells.Add(tc);
tb1.Rows.Add(tr1);
tr2 = new TableRow();
tr2.CssClass = "riga_hdr2";
for (Int32 x = 0, y = nStart; x < nHours; x++)
{
tc = new TableCell();
tc.CssClass = "cella_hdr2";
tc.Text = y.ToString().PadLeft(2, '0');
tr2.Cells.Add(tc);
if (y == 0 && x > 0)
{
tc = new TableCell();
tc.CssClass = "cella_hdr1";
tc.Text = dtDay.AddDays(z).ToString("dd MMMM yyyy");
tc.ColumnSpan = Math.Min(24, nHours - x );
z++;
tr1.Cells.Add(tc);
}
if (++y > 23)
y = 0;
}
tb1.Rows.Add(tr1);
tb1.Rows.Add(tr2);
this.Controls.Add(tb1);
ViewState["SelectedDate"] = dtDay;
ViewState["Hours"] = nHours;
ViewState["Start"] = nStart;
}
}
-- Pagina.aspx
-- Pagina.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
public partial class Default6 : System.Web.UI.Page
{
protected void btnIndietro_Click(object sender, EventArgs e)
{
Header1.Previous();
}
protected void btnAvanti_Click(object sender, EventArgs e)
{
Header1.Next();
}
protected void btnIndietroGiorno_Click(object sender, EventArgs e)
{
Header1.PreviousDay();
}
protected void btnAvantiGiorno_Click(object sender, EventArgs e)
{
Header1.NextDay();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Header1.Hours = 24;
Header1.Start = 3;
Header1.MakeControl();
}
}
}
Ho trovato la soluzione, ho inserito un DIV e lo stile funziona?!?
Ecco il codice modificato:
public void MakeControl()
{
Table tb1;
TableRow tr1, tr2;
TableCell tc;
Int32 z = 1;
Panel pn;
tb1 = new Table();
tb1.CssClass = "tabella_hdr1";
tb1.CellPadding = 0;
tb1.CellSpacing = 0;
tr1 = new TableRow();
tr1.CssClass = "riga_hdr1";
tc = new TableCell();
tc.CssClass = "cella_hdr1";
tc.ColumnSpan = Math.Min(24 - nStart, nHours);
// tc.Text = dtDay.ToString("dd MMMM yyyy");
pn = new Panel();
// pn.CssClass = "cella_hdr1";
pn.Height = Unit.Pixel(25);
pn.ToolTip = dtDay.ToString("dd MMMM yyyy");
pn.Controls.Add(new LiteralControl(pn.ToolTip));
tc.Controls.Add(pn);
tr1.Cells.Add(tc);
tb1.Rows.Add(tr1);
tr2 = new TableRow();
tr2.CssClass = "riga_hdr2";
for (Int32 x = 0, y = nStart; x < nHours; x++)
{
tc = new TableCell();
tc.CssClass = "cella_hdr2";
tc.Text = y.ToString().PadLeft(2, '0');
tr2.Cells.Add(tc);
if (y == 0 && x > 0)
{
tc = new TableCell();
tc.CssClass = "cella_hdr1";
// tc.Text = dtDay.AddDays(z).ToString("dd MMMM yyyy");
pn = new Panel();
// pn.CssClass = "cella_hdr1";
pn.ToolTip = dtDay.AddDays(z).ToString("dd MMMM yyyy");
pn.Height = Unit.Pixel(25);
pn.Controls.Add(new LiteralControl( pn.ToolTip ));
tc.Controls.Add(pn);
tc.ColumnSpan = Math.Min(24, nHours - x );
z++;
tr1.Cells.Add(tc);
}
if (++y > 23)
y = 0;
}
tb1.Rows.Add(tr1);
tb1.Rows.Add(tr2);
this.Controls.Add(tb1);
ViewState["SelectedDate"] = dtDay;
ViewState["Hours"] = nHours;
ViewState["Start"] = nStart;
}
Grazie comunque
Campioni del mondo!!!