Wednesday, May 12, 2010Implementing selected Grid rows in Gantt_ASP
To get the selected, yellow, row to function when pressing the Select link in the cell read on… 1: /// Add a Select button in the grid 2: Gantt_ASP1.Gantt.Grid.Columns.AddNew(PlexityHide.GTP.CellType.SingleText); 3: Gantt_ASP1.Gantt.Grid.Columns[2].DataSourceColumn = ""; 4: Gantt_ASP1.OnPostBackEvent += new EventHandler(Gantt_ASP1_OnPostBackEvent); 5: CellLayout cl = new CellLayout(); 6: cl.BackgroundColor = Color.Yellow; 7: cl.BackgroundUse = true; 8: cl.Name = "SelectedRow"; 9: Gantt_ASP1.Gantt.Grid.CellLayouts.Add(cl); The code above is added to the page load; it adds a column, it adds an eventhandler for OnPostBack, and it adds cellLayout that we will use to highlight the selected row. I also implement the OnCellContentTuning event to add a link in the cell that is in column 2 1: void Gantt_ASP1_OnCellContentTuning(Gantt_ASP aGantt, CellContentTuningArgs e) 2: { 3: if (e.Cell.Column.Index == 2) 4: { 5: if (e.Cell.GridNode != null) 6: { 7: string postbackref = "Select:" + Gantt_ASP1.GridNodeKey(e.Cell.GridNode); 8: e.Content = "<a href=\"javascript:" + Page.ClientScript.GetPostBackEventReference(aGantt, postbackref) + "\">Select</a>"; 9: } 10: } 11: } The implementation of the OnPostBack: 1: void Gantt_ASP1_OnPostBackEvent(object sender, EventArgs e) 2: { 3: string[] parts = Page.Request.Params[2].Split(':'); 4: if (parts.Length > 1) 5: { 6: if (parts[0] == "Select") 7: { 8: GridNode gn = Gantt_ASP1.GridNodeFromKey(parts[1]); 9: if (gn != null) 10: { 11: Gantt_ASP1.Gantt.Grid.FocusedCell = gn.GetCell(0); 12: this.ViewState["SelectedNode"] = parts[1]; 13: } 14: } 15: } 16: } In the code above I set the ViewState variable “SelectedNode” to the key of the GridNode And finally I implement the event OnClientSideChangesApplied to apply the CellLayout to the row that is defined by the ViewState variable: 1: protected void Gantt_ASP1_OnClientSideChangesApplied(object sender, EventArgs e) 2: { 3: string s = this.ViewState["SelectedNode"] as string; 4: if (s != null) 5: { 6: GridNode gn = Gantt_ASP1.GridNodeFromKey(s); 7: if (gn != null) 8: { 9: gn.SetCellLayoutOnAll(Gantt_ASP1.Gantt.Grid.CellLayouts.GetFromName("SelectedRow")); 10: } 11: } 12: 13: } Done. Subscribe to Posts [Atom] |
|
