Display specifc documents with where condition

web dev asked on May 29, 2020 17:34

Hello Dev i was trying to display data based on this code but display only 3 page type where field is true here is my code I already try it but get an error

private void GetDataRowOutput(DataRowView drv, StringBuilder sb, GroupedDataSource gpd)
    {
        sb.Append("<li><a href=\"")
            .Append(URLHelper.GetAbsoluteUrl(DocumentURLProvider.GetUrl(drv["NodeAliasPath"].ToString())))
            .Append("\" title=\"")
            .Append(drv["DocumentName"])
            .Append("\" class=\"")
            .Append(drv["ClassName"])
            .Append("\">")
            .Append(drv["DocumentName"])
            .Append("</a>")
            .Append("</li>");
        int nodeID = Convert.ToInt32(drv["NodeID"]);
        var items = gpd.GetGroupView(nodeID);
        if (items != null)
        {
            sb.Append("<ul>");
            foreach (var i in items) GetDataRowOutput(i, sb, gpd);
            sb.Append("</ul>");
        }
    }

    public string GetSiteMap()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<ul>");

        var ds = DocumentHelper.GetDocuments()
        .OnCurrentSite()
        .Columns("NodeLevel", "NodeOrder", "NodeName", "NodeParentID", "NodeAliasPath", "DocumentName", "NodeID", "ClassName")
        .OrderBy("NodeLevel, NodeOrder, NodeName")
        .Result;

        GroupedDataSource gpd = new GroupedDataSource(ds, "NodeParentID", "NodeLevel");
        var items = gpd.GetGroupView(0);
        foreach (DataRowView drv in items)
        {
            GetDataRowOutput(drv, sb, gpd);
        }
        sb.Append("</ul>");
        return sb.ToString();
    }

}

Recent Answers


David te Kloese answered on June 4, 2020 09:37

Hi,

What exactly is the Error you're getting?

I'm not sure the values of your StringBuilder in property SB are properly returend. As GetDataRowOutput() doesn't return the value and the value of sb is only passed as a property.

You say: display only 3 page type where field is true

There is no where clause or page type selection in your query so not sure if you want to filter?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.