11546 : Gantt_ASP, adding hyperlink in the grid

Question

I want to add a hyperlink “Delete” for each row in the grid

Answer

 

Add a extra column that has nothing in the DataSourceColumn:

        Gantt_ASP1.Gantt.Grid.Columns.AddNew(PlexityHide.GTP.CellType.SingleText);
        Gantt_ASP1.Gantt.Grid.Columns[1].DataSourceColumn = “”;

Then when the row is initiated, inject your callback link:

 

    void Grid_OnNodeInserted(Grid aGrid, NodeEventArgs e)
    {
        // For each new node we set up databind for subnodes…
        e.GridNode.SubNodes_DataSource = (e.GridNode.ListItemWhenDataBound() as DataRowView).CreateChildView(“subnodes”);

        string postbackref = “DELETE:” + Gantt_ASP1.GridNodeKey(e.GridNode.GetCell(1).GridNode);
        string deletecontent = “<a href=\”javascript:” + Page.ClientScript.GetPostBackEventReference(this, postbackref) + “\”>Delete</a>”;
        e.GridNode.GetCell(1).Content.Value = deletecontent;

        // and for time items
        GanttRow gr = Gantt.GanttRowFromGridNode(e.GridNode);
        gr.IncreaseRowHeightOnCollision = true;
        gr.IncreaseRow_SuggestedHeightPerItem = 20;
        gr.Layers[0].TimeItemLayout = “spacy”;
        gr.Layers[0].NameInDS_Identity = “id”;
        gr.Layers[0].NameInDS_Start = “start”;
        gr.Layers[0].NameInDS_Stop = “stop”;
        gr.Layers[0].DataSource = (e.GridNode.ListItemWhenDataBound() as DataRowView).CreateChildView(“timeitems”);
    }

Here I gave it a PostBack to the page (Page.ClientScript.GetPostBackEventReference(this…  )
So we need to make the page a IPostBackEventHandler
Just add IPostBackEventHandler behind the superclass Page:

public partial class _Default : System.Web.UI.Page, IPostBackEventHandler

Right click the IPostBackEventHandler and choose Implement interface:

Implement the handling code:

    private bool _deferActualDeleteUntilViewStateIsFullyApplied;
    private string _idToDelete;
    #region IPostBackEventHandler Members

    public void RaisePostBackEvent(string eventArgument)
    {
        string[] parts=eventArgument.Split(‘:’);
        if (parts.Length > 1)
        {
            if (parts[0] == “DELETE”)
            {
                _deferActualDeleteUntilViewStateIsFullyApplied = true;
                _idToDelete = parts[1];
            }
        }
    }

    #endregion

We do not want to delete directly, since the GridNodes are not sorted yet…
Instead we delete in the OnClientSideChangesApplied event, if applicable:

    protected void Gantt_ASP1_OnClientSideChangesApplied(object sender, EventArgs e)
    {
        if (_deferActualDeleteUntilViewStateIsFullyApplied)
        {
            GridNode gn_todelete = Gantt_ASP1.GridNodeFromKey(_idToDelete);
            if (gn_todelete != null && gn_todelete.ListItemWhenDataBound() != null)
            {

                (gn_todelete.ListItemWhenDataBound() as DataRowView).Delete();
            }
        }

     // Save the changes maybe…

    }