Domanda

Qualcuno ha usato GTP.NET di plexityhide per asp.net 3.5 come sto cercando di colorare le singole celle in base a una var che sto ricevendo da una query linq come segue

PilotDataContext pilot = new PilotDataContext();

var schedule = from x in pilot.slot_tbl_Schedules select x;

foreach (var s in schedule)
{
    if (s.AppointmentType == "Repair")
    {
        CellLayout cl = gn.GetCell(0).Layout.Clone() as CellLayout;
        gn.GetCell(0).Layout = cll;
        cl.BackgroundColor = Color.Red;
        cl.SelectedColor = Color.Red; 
    }
    else if (s.AppointmentType == "Service")
    {
        CellLayout cl = gn.GetCell(0).Layout.Clone() as CellLayout;
        gn.GetCell(0).Layout = cl;
        cl.BackgroundColor = Color.Blue;
    }
    else if (s.AppointmentType == "TravelTime")
    {
        CellLayout cl = gn.GetCell(0).Layout.Clone() as CellLayout;
        gn.GetCell(0).Layout = cl;
        cl.BackgroundColor = Color.Green;
    }
    else if (s.AppointmentType == "AnnualLeave")
    {
        CellLayout cl = gn.GetCell(0).Layout.Clone() as CellLayout;
        gn.GetCell(0).Layout = cl;
        cl.BackgroundColor = Color.Yellow;
    }
}

la sintassi nell'istruzione if è ciò che hanno raccomandato, chiunque può aiutare su questo

Molte grazie

È stato utile?

Soluzione

Assicurati di impostare CellLayout.BackgroundUse = true. In caso contrario, il colore di sfondo viene ignorato.

E poiché usi ASP.NET cellLayouts genererà un css, quindi devi aggiungere i nuovi CellLayout clonati alla raccolta su CellLayouts:

Gantt_ASP.Gantt.Grid.CellLayouts.Add (cl);

Altri suggerimenti

Dim cl2 As CellLayout = TryCast(e.GridNode.GetCell(4).Layout.Clone(), CellLayout)

cl2.SelectedColor = Color.Red
cl2.FontColor = Color.Red
cl2.BackgroundColor = Color.Blue
cl2.BackgroundUse = True ' when is true background color change 
e.GridNode.GetCell(4).Layout = cl2

funziona bene ..... :)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top