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

Hierarchical problem-I think

1 Answer 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anon
Top achievements
Rank 1
Anon asked on 08 Jul 2008, 11:16 AM
Hi all,

I ran into a problem with a 3 level grid. I am using a grid as a forum (comments) section. I have the masterview as topic, and detail views for comments and replys. The topic and reply work fine, the details and new windows pop up just like they should. However the comments section isnt working as it should. The first row works for both details and edit however the rows fallowing do not open a window, instead throwing a  JScript error claiming [rowIdex] has no properties. Ive included all of the relivant JS,ASPX and VB for the Grid In hopes that one of you know how to fix what must be a hierachical problem (at least I hope its something easy to fix) I have tried different methods for the last 3 days to solve it with no improvement. Thanks in advance.

Anon

JS/ASPX
 
                <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
 
                    <script type="text/javascript">  
                            
              function InsertNewComment(id, rowIndex)  
            {  
                var grid = $find("<%= RadGridDis.ClientID %>");  
                  
                var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();  
                grid.get_masterTableView().selectItem(rowControl, true);  
                          
                window.radopen("EditPages/NewComment.aspx?TopicID=" + id, "UserListDialog");  
                return false;  
            }  
           
             function ShowViewComment(id, rowIndex)  
            {  
                var grid = $find("<%= RadGridDis.ClientID %>");  
                  
               var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();  
                grid.get_masterTableView().selectItem(rowControl, true);  
                          
                window.radopen("EditPages/ViewComment.aspx?CommentID=" + id, "UserListDialog");  
                return false;  
            }  
             function InsertNewReply(id, rowIndex)  
            {  
                var grid = $find("<%= RadGridDis.ClientID %>");  
                  
                var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();  
                grid.get_masterTableView().selectItem(rowControl, true);  
                          
                window.radopen("EditPages/NewReply.aspx?CommentID=" + id, "UserListDialog");  
                return false;  
            }  
               function ShowViewReply(id, rowIndex)  
            {  
                var grid = $find("<%= RadGridDis.ClientID %>");  
                  
                var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();  
                grid.get_masterTableView().selectItem(rowControl, true);  
                          
                window.radopen("EditPages/ViewReply.aspx?ReplyID=" + id, "UserListDialog");  
                return false;  
            }  
            
            function NewComment()  
            {  
               window.radopen("EditPages/NewComment.aspx", "UserListDialog");  
               return false;  
            }  
              
             
            function refreshGrid(arg)  
            {  
             if(!arg)  
             {  
             $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");              
                }  
                else  
                {  
             $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate");              
                }  
            }  
         
                    </script> 
 
                </telerik:RadCodeBlock> 
                    <telerik:radwindowmanager id="RadWindowManager1" runat="server" Skin="Vista">  
            <windows> 
                <telerik:RadWindow id="UserListDialog" title="User List Dialog" Height="600px" Width="720px" Runat="server" 
                Left="150px" ReloadOnShow="true" Modal="true" VisibleOnPageLoad="true" Visible="false" /> 
            </windows> 
        </telerik:radwindowmanager> 
                 
                        <telerik:RadGrid ID="RadGridDis" runat="server" Skin="Vista" Width="97%" DataSourceID="SqlDataSource1" 
                            GridLines="None" AutoGenerateColumns="False" AllowPaging="True"   
                            AllowSorting="True" EnableAJAX="True" 
                            PageSize="20" EnableLinqExpressions="False"   
                            OnItemCreated="RadGridDis_ItemCreated" ShowFooter="True" ShowStatusBar="True">  
                            <MasterTableView DataKeyNames="TopicID" DataSourceID="SqlDataSource1" CommandItemDisplay="Top" 
                                Name="Master">  
                                <DetailTables> 
                                    <telerik:GridTableView runat="server" DataSourceID="SqlDataSource2" DataKeyNames="CommentID" 
                                        Name="SubMaster" NoDetailRecordsText="No Comments Posted"   
                                        ClientDataKeyNames="CommentID">  
                                        <DetailTables> 
                                            <telerik:GridTableView runat="server" SortExpression="ReplyID"   
                                                DataKeyNames="ReplyID" DataSourceID="SqlDataSource3" Name="Sub"   
                                                NoDetailRecordsText="No reply posted">  
                                                <ParentTableRelation> 
                                                  
                                                    <telerik:GridRelationFields DetailKeyField="CommentID"  MasterKeyField="CommentID" /> 
                                                </ParentTableRelation> 
                                                <RowIndicatorColumn Visible="False">  
                                                    <HeaderStyle Width="20px" /> 
                                                </RowIndicatorColumn> 
                                                <ExpandCollapseColumn Resizable="False" Visible="False">  
                                                    <HeaderStyle Width="20px" /> 
                                                </ExpandCollapseColumn> 
                                                <Columns> 
                                                    <telerik:GridBoundColumn DataField="Postby" HeaderText="Posted by" SortExpression="Postby" 
                                                    UniqueName="Postby">  
                                                    </telerik:GridBoundColumn> 
                                                    <telerik:GridBoundColumn DataField="Title" HeaderText="Reply Title" UniqueName="title" SortExpression="Title">  
                                                    </telerik:GridBoundColumn> 
                                                    <telerik:GridBoundColumn DataField="CreateDate" DataFormatString="{0:d}" HeaderText="Posted on" 
                                                        UniqueName="CreateDate" SortExpression="CreateDate">  
                                                    </telerik:GridBoundColumn> 
                                                    <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">  
                                                        <ItemTemplate> 
                                                            <asp:HyperLink ID="ViewReply" runat="server" ImageUrl="~/images/icons/comment.png" 
                                                                Title="View Reply"></asp:HyperLink> 
                                                        </ItemTemplate> 
                                                    </telerik:GridTemplateColumn> 
                                                </Columns> 
                                                <EditFormSettings> 
                                                    <PopUpSettings ScrollBars="None" /> 
                                                </EditFormSettings> 
                                            </telerik:GridTableView> 
                                        </DetailTables> 
                                        <ParentTableRelation> 
                                            <telerik:GridRelationFields DetailKeyField="TopicID" MasterKeyField="TopicID" /> 
                                        </ParentTableRelation> 
                                        <RowIndicatorColumn Visible="False">  
                                            <HeaderStyle Width="20px" /> 
                                        </RowIndicatorColumn> 
                                        <ExpandCollapseColumn Resizable="False">  
                                            <HeaderStyle Width="20px" /> 
                                        </ExpandCollapseColumn> 
                                        <Columns> 
                                            <telerik:GridBoundColumn HeaderText="Comment Title" UniqueName="title" DataField="Title" SortExpression="Title">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="PostBy" HeaderText="Posted by" UniqueName="Postby" SortExpression="PostBy">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="CreateDate" HeaderText="Date Posted"   
                                                UniqueName="CreateDate" SortExpression="CreateDate" DataFormatString="{0:d}">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridTemplateColumn UniqueName="PriorityComment" HeaderText="">  
                                                <ItemTemplate> 
                                                    <asp:Image ID="PriorityComment" Boarderwidth="0px" runat="server" ImageUrl="~/images/icons/normal.gif" 
                                                        AlternateText="Urgent" Style="float: right;" /> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridTemplateColumn UniqueName="TemplateEditColumn1">  
                                                <ItemTemplate> 
                                                    <asp:HyperLink ID="ViewComment1" runat="server" ImageUrl="~/images/icons/comment.png" 
                                                        Title="View Comment"></asp:HyperLink> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">  
                                                <ItemTemplate> 
                                                    <asp:HyperLink ID="NewReply" runat="server" ImageUrl="~/images/icons/reply.png" Title="Post Reply"></asp:HyperLink> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                        </Columns> 
                                        <EditFormSettings> 
                                            <PopUpSettings ScrollBars="None" /> 
                                        </EditFormSettings> 
                                    </telerik:GridTableView> 
                                </DetailTables> 
                                <CommandItemTemplate> 
                                    <href="EditPages/NewTopic.aspx" onclick="return NewTopic();">Add New Topic</a> 
                                </CommandItemTemplate> 
                                <ParentTableRelation> 
                                    <telerik:GridRelationFields DetailKeyField="TopicID" MasterKeyField="TopicID" /> 
                                </ParentTableRelation> 
                                <RowIndicatorColumn Visible="False">  
                                    <HeaderStyle Width="20px"></HeaderStyle> 
                                </RowIndicatorColumn> 
                                <ExpandCollapseColumn Resizable="False">  
                                    <HeaderStyle Width="20px"></HeaderStyle> 
                                </ExpandCollapseColumn> 
                                <Columns> 
                                    <telerik:GridBoundColumn DataField="TopicTitle" HeaderText="Topic Title" SortExpression="TopicTitle" 
                                        UniqueName="TopicTitle">  
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn DataField="TopicCreate" HeaderText="Create on" SortExpression="TopicCreate" 
                                        UniqueName="TopicCreate" DataType="System.DateTime"   
                                        DataFormatString="{0:d}">  
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn DataField="TopicCreater" DataType="System.Int32" HeaderText="Posted by" 
                                        SortExpression="TopicCreater" UniqueName="TopicCreater">  
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">  
                                        <ItemTemplate> 
                                            <asp:HyperLink ID="NewComment" runat="server" ImageUrl="~/images/icons/comment_add.png" 
                                                Title="Add comment"></asp:HyperLink> 
                                        </ItemTemplate> 
                                    </telerik:GridTemplateColumn> 
                                </Columns> 
                                <EditFormSettings> 
                                    <PopUpSettings ScrollBars="None"></PopUpSettings> 
                                </EditFormSettings> 
                            </MasterTableView> 
                            <ClientSettings> 
                                <Selecting AllowRowSelect="True" /> 
                            </ClientSettings> 
                        </telerik:RadGrid> 
                     
 

VB

Imports System  
Imports System.Data  
Imports System.Configuration  
Imports System.Collections  
Imports System.Web  
Imports System.Web.Security  
Imports System.Web.UI  
Imports System.Web.UI.WebControls  
Imports Telerik.Web.UI  
 
Imports System.Data.SqlClient  
Partial Class Discussion  
    Inherits System.Web.UI.Page  
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
        If Not IsPostBack Then  
            RadGridDis.SelectedIndexes.Add(1, 0, 1, 0, 1)  
              
        End If  
    End Sub  
 
    Protected Sub RadGridDis_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGridDis.ItemDataBound  
        Try  
            If e.Item.OwnerTableView.Name = "SubMaster" Then  
 
 
                If e.Item.ItemType = GridItemType.Item Or e.Item.ItemType = GridItemType.AlternatingItem Then  
                    Dim objRow As DataRowView  
                    objRow = e.Item.DataItem  
                    Dim tmpImage As Image  
 
                    tmpImage = CType(e.Item.FindControl("PriorityComment"), Image)  
                    tmpImage.ImageUrl = "images/icons/" & Trim(objRow("Urgent")) & ".gif" 
 
                End If  
 
            End If  
        Catch ex As Exception  
            Common.createErrorLog(Server.MapPath("Logs/"), "Error ====> " & ex.Message & " Time Occured:" & DateTime.Now & " Page: " & Request.FilePath())  
        End Try  
    End Sub  
    Protected Sub RadGridDis_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs)  
 
        Try  
            If e.Item.OwnerTableView.Name = "Master" Then  
                If TypeOf e.Item Is GridDataItem Then  
                    Dim viewLink3 As HyperLink = DirectCast(e.Item.FindControl("NewComment"), HyperLink)  
                    viewLink3.Attributes("href") = "#" 
                    viewLink3.Attributes("onclick") = [String].Format("return InsertNewComment('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("TopicID"), e.Item.ItemIndex)  
 
 
                End If  
 
            End If  
 
            If e.Item.OwnerTableView.Name = "SubMaster" Then  
                If TypeOf e.Item Is GridDataItem Then  
                    Dim viewLink2 As HyperLink = DirectCast(e.Item.FindControl("ViewComment1"), HyperLink)  
                    viewLink2.Attributes("href") = "#" 
                    viewLink2.Attributes("onclick") = [String].Format("return ShowViewComment('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("CommentID"), e.Item.ItemIndex)  
 
 
                End If  
 
            End If  
            If e.Item.OwnerTableView.Name = "SubMaster" Then  
                If TypeOf e.Item Is GridDataItem Then  
                    Dim viewLink2 As HyperLink = DirectCast(e.Item.FindControl("NewReply"), HyperLink)  
                    viewLink2.Attributes("href") = "#" 
                    viewLink2.Attributes("onclick") = [String].Format("return InsertNewReply('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("CommentID"), e.Item.ItemIndex)  
 
 
                End If  
 
            End If  
            If e.Item.OwnerTableView.Name = "Sub" Then  
                If TypeOf e.Item Is GridDataItem Then  
                    Dim viewLink As HyperLink = DirectCast(e.Item.FindControl("ViewReply"), HyperLink)  
                    viewLink.Attributes("href") = "#" 
                    viewLink.Attributes("onclick") = [String].Format("return ShowViewReply('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ReplyID"), e.Item.ItemIndex)  
                End If  
            End If  
 
        Catch ex As Exception  
            Common.createErrorLog(Server.MapPath("Logs/"), "Error ====> " & ex.Message & " Time Occured:" & DateTime.Now & " Page: " & Request.FilePath())  
        End Try  
    End Sub  
     
End Class 

Thanks again for any help.

Anon

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 09 Jul 2008, 08:18 AM
Hello Anon,

Could you please try setting the <ParentTableRelation> tags inside the detail tables instead of the parent tables. For example, the parent relation between the MasterTableView "Master" and its detail table "SubMaster" needs to go inside the "Submaster".

I hope this helps, as I could not identify any other errors in RadGrid's definition.

Best wishes,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Anon
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or