This is a migrated thread and some comments may be shown as answers.

Self Hierarchy Grid's Child Rows bounded twice Issue

11 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bharathwajan Venkatanarayanan
Top achievements
Rank 1
Bharathwajan Venkatanarayanan asked on 21 Oct 2009, 05:22 PM
The Self Hierarchy grid's Child rows bound correctly if we bind the grid source in the Page Load event.
If we bind the Self  Hierarchy Grid in the button click event the child rows are bounded twice. The child rows first bounded under the parent row and again bounded with the grid(with the parent row degree).

We used datatable as to bind the grid and rest of the things are same as explained in the below exmaple link
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/selfreferencing/defaultcs.aspx

11 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 27 Oct 2009, 08:35 AM
Hello Bharathwajan,

Complex features like hierarchy, grouping, custom edit forms, etc. are supported with advanced binding with NeedDataSource event handling or data source controls only. Hence you will need to modify your logic to utilize one of these binding modes and build your self-referencing hierarchy.

Sincerely yours,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Krishnan LN
Top achievements
Rank 1
answered on 18 Feb 2010, 06:47 AM
Hi i have the same problem as yours now. 

My problem is
I use a self referencing grid. Im binding a List which has 2 objects. The 1st object has a property called ID set to 1 and ParentID set to 0. The second object has ParentID set to ID for FIrst Object(1). Now when i try to bind the list as datasource to the grid in Page Load,
I get the 1st record displayed and 2nd record as child to first record. The problem is in addition to that, i recieve a duplicate second record in the same level as 1st record.

Any help is appreciated.





Can you let me know how did u solve the problem
0
Pavlina
Telerik team
answered on 18 Feb 2010, 04:11 PM
Hi Krishnan,

Unfortunately, based on the provided information it is hard to determine what is causing this erroneous behavior. Could you please send us a sample where we could replicate the issue in order to debug it locally and get to the source of the issue?

Best wishes,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
ali zubair
Top achievements
Rank 1
answered on 18 Sep 2010, 10:00 PM
Hi,
I am facing same problem like Krishnan LN is facing. in my database i have self join case. Let us suppose there are two records in database like EmpId1 has parentId null and empID2 has parentID 1. so grid should show records like
  • EmpID1
  •      EmpID2

but grid shows records like
EmpID1
     EmpID2
EmpID2


so empID2 repeats twice. hope this example clears the question.
I have followed same example given in following link except i bind grid in code behind file.
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/selfreferencing/defaultcs.aspx

so how can i solve this issue.????????????

One more question that can i use paging in self hierarchical grid??????

Your quick response is highly appreciated. thanks.

0
Pavlina
Telerik team
answered on 21 Sep 2010, 04:13 PM
Hi Ali,

To track the issue further, it will be best if you open a formal support ticket and send us a runnable sample. We will debug it locally and get back to you with a suitable resolution.

Greetings,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
kannan
Top achievements
Rank 1
answered on 13 Nov 2010, 09:22 AM
Hi,
   i am also facing the same issue. how to solve this issue ?...
 
0
Pavlina
Telerik team
answered on 15 Nov 2010, 06:01 PM
Hello Kannan,

In order to help you resolve the issue I will need to first reproduce it on my side. Could you please provide here the code of the sample (markup and code-behind if any)?

Thank you.

Regards,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
amita
Top achievements
Rank 1
answered on 10 Dec 2010, 06:40 AM
Hi,

I am facing the same problem. Has anyone got solution for this ?

ASPX

  <telerik:RadTreeList runat="server" ID="RadTreeList3" DataKeyNames="ElementID" ParentDataKeyNames="ParentID"
                OnDataBound="RadTreeList3_DataBound" OnNeedDataSource="RadTreeList3_NeedDataSource"
                AllowRecursiveSelection="true" ClientSettings-ClientEvents-OnItemDblClick="RowDblClick"
                 AllowMultiItemSelection="false"   >
                <Columns>
                    <telerik:TreeListSelectColumn HeaderStyle-Width="60px">
                    </telerik:TreeListSelectColumn>
                    <telerik:TreeListTemplateColumn DataField="CompName" HeaderText="CompName">
                        <ItemTemplate>
                            <table>
                                <tr>
                                    <td align="left">
                                        <asp:LinkButton ID="lnkOpenContentFilePath" runat="server" Text='<%# Eval("CompName") %>' OnClick="lnkOpenContentFilePath_Click"></asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:TreeListTemplateColumn>
                </Columns>
            </telerik:RadTreeList>

ASPX.CS
===========

 SqlConnection conn = null;

    DataSet ds = null;
    SqlDataAdapter da = null;
    private void BindGrid()
    {

        String ConnString = ConfigurationManager.ConnectionStrings["PSAConnectionString"].ConnectionString;
        conn = new SqlConnection(ConnString);

        SqlCommand cmd = new SqlCommand("SELECT [ElementID],[ParentID], [CompName], [Occurrences] FROM [StructureElements] WHERE ([StructureID] = 304)", conn);

        ds = new DataSet();
        da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        RadGrid1.DataSource = ds;

    }
    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        BindGrid();

    }

    protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
    {
        if (e.Column is GridExpandColumn)
        {
            e.Column.Visible = false;
        }
        else if (e.Column is GridBoundColumn)
        {
            e.Column.HeaderStyle.Width = Unit.Pixel(100);
        }

        if (e.Column.UniqueName == "ElementID" || e.Column.UniqueName == "ParentID")
            e.Column.Visible = false;

    }
    public void Page_PreRenderComplete(object sender, EventArgs e)
    {
        HideExpandColumnRecursive(RadGrid1.MasterTableView);
    }

    public void HideExpandColumnRecursive(GridTableView tableView)
    {
        GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
        foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
        {
            foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
            {
                nestedView.Style["border"] = "0";

                Label MyExpandCollapseButton = (Label)nestedView.ParentItem.FindControl("MyExpandCollapseButton");
                if (nestedView.Items.Count == 0)
                {
                    if (MyExpandCollapseButton != null)
                    {
                        MyExpandCollapseButton.Style["visibility"] = "hidden";
                    }
                    nestedViewItem.Visible = false;
                }
                else
                {
                    if (MyExpandCollapseButton != null)
                    {
                        MyExpandCollapseButton.Style.Remove("visibility");
                    }
                }

                if (nestedView.HasDetailTables)
                {
                    HideExpandColumnRecursive(nestedView);
                }
            }
        }
    }

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        CreateExpandCollapseButton(e.Item, "CompName");

        if (e.Item is GridHeaderItem && e.Item.OwnerTableView != RadGrid1.MasterTableView)
        {
            e.Item.Style["display"] = "none";
        }

        if (e.Item is GridNestedViewItem)
        {
            e.Item.Cells[0].Visible = false;
        }
    }

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        CreateExpandCollapseButton(e.Item, "CompName");
    }

    public void CreateExpandCollapseButton(GridItem item, string columnUniqueName)
    {
        if (item is GridDataItem)
        {
            if (item.FindControl("MyExpandCollapseButton") == null)
            {
                Label label = new Label();
                label.ID = "MyExpandCollapseButton";

                int level = item.ItemIndexHierarchical.Split(':').Length - 1;

                label.Style["margin-left"] = level * 15 + "px";

                TableCell cell = ((GridDataItem)item)[columnUniqueName];
                cell.Controls.Add(label);
                cell.Controls.Add(new LiteralControl("&nbsp;"));
                CheckBox chk = new CheckBox();
                chk.Attributes.Add("onclick", "OnCheckBoxCheckChanged(this)");
                cell.Controls.Add(chk);
                cell.Controls.Add(new LiteralControl(((GridDataItem)item).GetDataKeyValue(columnUniqueName).ToString()));
            }
        }
    }


    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {        
        if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1 || Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("4.0") != -1)
        {
            RadGrid1.MasterTableView.FilterExpression = @"it[""ParentID""] = Convert.DBNull";
        }
        else
        {
            RadGrid1.MasterTableView.FilterExpression = "ParentID IS NULL";
        }
    }


Please let me know.. where i am doing the mistake.
0
Pavlina
Telerik team
answered on 10 Dec 2010, 04:11 PM
Hello Amita,

Can you please check what is the result when you bind the RadTreeList control to the same
datasource?

All the best,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
John Chatt
Top achievements
Rank 1
answered on 18 Jan 2011, 09:58 PM

I am also having this problem. Has no solution been posted yet?

here is my code

Front End:

<rad:RadGrid ID=
"rgFeedback" DataSourceID="sdsFeedback" AllowPaging="true" AllowSorting="true"
    OnItemCommand="rgFeedback_ItemCommand" runat="server" ShowHeader="true" OnNeedDataSource="rgFeedback_NeedDataSource"
     OnItemCreated="rgFeedback_ItemCreated" OnItemDataBound="rgFeedback_ItemDataBound" OnColumnCreated="rgFeedback_ColumnCreated">
    <ExportSettings ExportOnlyData="true" FileName="Users" IgnorePaging="true" OpenInNewWindow="true">
        <Excel FileExtension="xls" Format="Html" />
        <Pdf Author='Me' Title="Search Discussions" />
    </ExportSettings>
    <PagerStyle AlwaysVisible="true" Mode="NextPrevNumericAndAdvanced" PageButtonCount="5"
        ShowPagerText="true" Position="TopAndBottom" />
    <MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" AutoGenerateColumns="false" CommandItemDisplay="Top"
    DataKeyNames="ParentFeedBackID, FeedBackID, Feedback">
        <SelfHierarchySettings ParentKeyName="ParentFeedBackID" KeyName="FeedBackID" />
        <Columns>
            <rad:GridBoundColumn HeaderText="Comment" DataField="Feedback" SortExpression="Feedback"
                EmptyDataText="--" UniqueName="Feedback" />
            <rad:GridTemplateColumn HeaderText="Date" SortExpression="CreateDateTime" HeaderStyle-Wrap="false" ItemStyle-Wrap="false" ItemStyle-VerticalAlign="Top">
                <ItemTemplate>
                    Date
                </ItemTemplate>
            </rad:GridTemplateColumn>
            <rad:GridTemplateColumn HeaderText="Document ID" SortExpression="DocumentID" ItemStyle-Wrap="false"
                ItemStyle-VerticalAlign="Top" HeaderStyle-Wrap="false">
                <ItemTemplate>
                    <asp:HyperLink ID="hlDocumentID" runat="server" NavigateUrl='<%# String.Format("Document.aspx?DocumentID={0}", ((String) (Eval("DocumentID") == DBNull.Value ? "" : Eval("DocumentID"))).Replace(":", Server.UrlEncode(":"))) %>'
                        Text='<%# GetDocumentID() %>' Enabled='<%# GetDocumentLinkEnabled() %>' />
                </ItemTemplate>
            </rad:GridTemplateColumn>
            <rad:GridHyperLinkColumn HeaderText="Workflow" SortExpression="WorkflowName" DataNavigateUrlFields="SubjectedDocumentRevisionID, WorkflowID"
                DataNavigateUrlFormatString="~/client/DocumentViewer.aspx?DocumentRevisionID={0}&tab=workflow&WorkflowID={1}"
                DataTextField="WorkflowName" />
            <rad:GridTemplateColumn HeaderText="User" SortExpression="UserID" ItemStyle-Wrap="false"
                ItemStyle-VerticalAlign="Top" HeaderStyle-Wrap="false">
                <ItemTemplate>
                    <a href='<%# ResolveClientUrl("~/admin/User.aspx?UserID=" + Eval("UserID")) %>' title='View User'>
                        <%# String.Format("{0} - {1} {2}", Eval("UserID"), Eval("FirstName"), Eval("LastName")) %>
                    </a>
                </ItemTemplate>
            </rad:GridTemplateColumn>
            <rad:GridTemplateColumn HeaderText="Delete" ItemStyle-VerticalAlign="Top">
                <ItemTemplate>
                    <asp:LinkButton ID="lbDelete" CssClass="deleteIcon" CommandName="DeleteFeedback"
                        OnClientClick="return confirm('Are you sure you want to delete this comment?');"
                        CommandArgument='<%# Eval("FeedbackID") %>' ToolTip="Delete this comment" runat="server" />
                </ItemTemplate>
            </rad:GridTemplateColumn>
        </Columns>
        <CommandItemTemplate>
            <table class='rgCommandTable' style='width: 100%;'>
                <tr>
                    <td align="left">
                          
                    </td>
                    <td align="right">
                        <asp:ImageButton ID="ibExportToExcel" CommandName="ExportToExcel" ImageUrl="~/ui/images/excel.png"
                            runat="server" />
                          
                        <asp:ImageButton ID="ibExportToPdf" CommandName="ExportToPdf" ImageUrl="~/ui/images/doc_pdf.png"
                            runat="server" />
                          
                        <asp:ImageButton ID="ibExportToWord" CommandName="ExportToWord" ImageUrl="~/ui/images/page_white_word.png"
                            runat="server" />
                    </td>
                </tr>
            </table>
        </CommandItemTemplate>
    </MasterTableView>
    <ClientSettings AllowExpandCollapse="true" />
</rad:RadGrid>

Code Behind:

protected void rgFeedback_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    rgFeedback.DataSource = sdsFeedback;
}

I have tried setting the DataSource both in the front end and in the code behind.
both ways that I do it a get a duplicate row
0
Pavlina
Telerik team
answered on 24 Jan 2011, 02:21 PM
Hi Bharathwajan,

If you want to display a tree-like structure, Set the FilterExpression property of the MasterTableView to filter out all items except those that belong at the root level of the hierarchy. Note that this must be done on Page_Load, so that the filter does not apply to any detail tables. 

In your case in order to avoid one and the same value to repeat twice you should also set the RadGrid.MasterTableView.FilterExpression property on Page_Load. More information is available here:
http://www.telerik.com/help/aspnet-ajax/grdselfreferencinghierarchy.html

Additionally, you can refer to this article for more information on RadGrid FilterExpressions.

I hope this helps.

Kind regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Bharathwajan Venkatanarayanan
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Krishnan LN
Top achievements
Rank 1
ali zubair
Top achievements
Rank 1
kannan
Top achievements
Rank 1
amita
Top achievements
Rank 1
John Chatt
Top achievements
Rank 1
Share this question
or