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

[Solved] master/detail doesn't work on rowclick

2 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mydatafactory
Top achievements
Rank 1
Mydatafactory asked on 15 Jul 2009, 09:17 AM
Hello,

Based on the demo 'Master/Detail Grids' I've made a .aspx page. Although the SQL-statements work properly when I test them, the rowclick in the mastergrid (gvTasksDataSteward) doesn't show any value in the detailsgrid (gvDetails). I've checked the demo thorougly but can't find whats missing/going wrong.

The aspx:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">  
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">  
    <%--master--%> 
    <telerik:RadGrid ID="gvTasksDataSteward" runat="server" AutoGenerateColumns="False" 
        DataSourceID="dsTasks" GridLines="None" Skin="Office2007">  
        <ClientSettings EnablePostBackOnRowClick="true" AllowKeyboardNavigation="True">  
            <Selecting AllowRowSelect="true" /> 
        </ClientSettings> 
        <MasterTableView DataSourceID="dsTasks" Name="DatastewardTasks" DataKeyNames="TaskId" 
            AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" 
            EditMode="PopUp">  
            <RowIndicatorColumn Visible="False">  
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn Visible="False" Resizable="False">  
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandProject">  
                    <HeaderStyle Width="20px" /> 
                </telerik:GridEditCommandColumn> 
                <telerik:GridBoundColumn DataField="TaskId" HeaderText="TaskId" UniqueName="TaskId" 
                    Visible="false" ReadOnly="true">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="CompanyName" HeaderText="Company" SortExpression="Company" 
                    UniqueName="Company">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="ProjectName" HeaderText="Project" SortExpression="ProjectName" 
                    UniqueName="ProjectName">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="TaskDescription" HeaderText="TaskDescription" 
                    SortExpression="TaskDescription" UniqueName="TaskDescription">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Remarks" HeaderText="Remarks" SortExpression="Remarks" 
                    UniqueName="Remarks">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="StartDate" DataType="System.DateTime" HeaderText="StartDate" 
                    SortExpression="StartDate" UniqueName="StartDate" DataFormatString="{0:d}">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="SoortBewerking" HeaderText="SoortBewerking" SortExpression="SoortBewerking" 
                    UniqueName="SoortBewerking">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="RealHours" DataType="System.Decimal" HeaderText="RealHours" 
                    SortExpression="RealHours" UniqueName="RealHours" Visible="false">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="StatusId" UniqueName="StatusId" Visible="false" 
                    ReadOnly="true">  
                </telerik:GridBoundColumn> 
                <telerik:GridButtonColumn ButtonType="PushButton" UniqueName="Accept" Text="Accept" 
                    ImageUrl="~/Images/OK.png" ShowInEditForm="false" CommandName="Accepted">  
                </telerik:GridButtonColumn> 
                <telerik:GridButtonColumn ButtonType="PushButton" UniqueName="NotAccept" Text="Not Accept" 
                    ImageUrl="~/Images/OK.png" ShowInEditForm="false" CommandName="NotAccepted">  
                </telerik:GridButtonColumn> 
                <telerik:GridButtonColumn ButtonType="PushButton" UniqueName="Executed" Text="Executed" 
                    ImageUrl="~/images/11new.gif" ShowInEditForm="false" CommandName="Executed" ConfirmText="Executed?">  
                </telerik:GridButtonColumn> 
            </Columns> 
            <EditFormSettings CaptionFormatString="Edit: {0}" CaptionDataField="ProjectName">  
                <PopUpSettings ScrollBars="Auto"></PopUpSettings> 
                <EditColumn ButtonType="ImageButton" CancelText="Cancel Edit" UpdateText="Update Task" 
                    InsertText="Insert User" UniqueName="EditCommandColumn">  
                </EditColumn> 
                <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle> 
            </EditFormSettings> 
        </MasterTableView> 
    </telerik:RadGrid> 
    <%--Details--%> 
    <telerik:RadGrid ID="gvDetails" runat="server" AutoGenerateColumns="False" DataSourceID="dsFiles" 
        GridLines="None" Skin="Office2007">  
        <MasterTableView Name="Details" DataSourceID="dsFiles" DataKeyNames="FileId">  
            <RowIndicatorColumn Visible="False">  
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn Visible="False" Resizable="False">  
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridBoundColumn DataField="FileName" HeaderText="FileName" SortExpression="FileName" 
                    UniqueName="FileName">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="ProjectId" DataType="System.Int32" HeaderText="ProjectId" 
                    SortExpression="ProjectId" UniqueName="ProjectId">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="FileId" HeaderText="FileId" SortExpression="FileId" 
                    UniqueName="FileId" Visible="false">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="FileSaveAs" HeaderText="FileSaveAs" SortExpression="FileSaveAs" 
                    UniqueName="FileSaveAs" Visible="false">  
                </telerik:GridBoundColumn> 
            </Columns> 
            <EditFormSettings> 
                <PopUpSettings ScrollBars="None"></PopUpSettings> 
            </EditFormSettings> 
        </MasterTableView> 
        <ClientSettings AllowKeyboardNavigation="True" EnablePostBackOnRowClick="True">  
        <Selecting AllowRowSelect="true" /> 
        </ClientSettings> 
    </telerik:RadGrid> 
      
      
    <asp:SqlDataSource ID="dsTasks" runat="server" ConnectionString="<%$ ConnectionStrings:dsBewerkingenConnectionString %>" 
        SelectCommand="SELECT tblTasks.ReadyDate, tblTasks.TaskDescription, tblTasks.Remarks, tblTasks.TaskId, tblTasks.StartDate, tblTasks.StatusId, tblTasks.RealHours, tblBewerkingen.SoortBewerking, tblStatusTasks.StatusNam, tblProjects.ProjectName, tblCompany.CompanyName FROM tblTasks INNER JOIN tblStatusTasks ON tblTasks.StatusId = tblStatusTasks.StatusId LEFT OUTER JOIN tblProjects ON tblTasks.ProjectId = tblProjects.ProjectId LEFT OUTER JOIN tblBewerkingen ON tblTasks.BewerkingId = tblBewerkingen.BewerkingId LEFT OUTER JOIN tblCompany ON tblProjects.CompanyId = tblCompany.CompanyId WHERE (tblTasks.StatusId IN (7, 4)) AND (tblTasks.UserId = @UserId)" 
        DeleteCommand="DELETE FROM [tblTasks] WHERE [TaskId] = @TaskId" InsertCommand="INSERT INTO [tblTasks] ([ProjectId], [BewerkingId], [UserId], [ReadyDate], [TaskDescription], [Remarks], [Date], [StartDate], [EstimatedHours], [RealHours], [NumberArticles], [EstimatedReadyDate], [Status_actief], [StatusId], [DateSendDataSteward]) VALUES (@ProjectId, @BewerkingId, @UserId, @ReadyDate, @TaskDescription, @Remarks, @Date, @StartDate, @EstimatedHours, @RealHours, @NumberArticles, @EstimatedReadyDate, @Status_actief, @StatusId, @DateSendDataSteward)" 
        UpdateCommand="UPDATE [tblTasks] SET [ReadyDate] = @ReadyDate,  [RealHours] = @RealHours, [StatusId] = @StatusId WHERE [TaskId] = @TaskId">  
        <SelectParameters> 
<asp:SessionParameter DefaultValue="0" Name="UserId" SessionField="UserId"   
                Type="Int32" /> 
                        </SelectParameters> 
        <DeleteParameters> 
            <asp:Parameter Name="TaskId" Type="Int32" /> 
        </DeleteParameters> 
        <UpdateParameters> 
            <asp:Parameter Name="ReadyDate" Type="DateTime" /> 
            <asp:Parameter Name="RealHours" Type="Decimal" /> 
            <asp:Parameter Name="StatusId" /> 
            <asp:Parameter Name="TaskId" /> 
        </UpdateParameters> 
        <InsertParameters> 
            <asp:SessionParameter Name="ProjectId" SessionField="ProjectId" Type="Int32" /> 
            <asp:Parameter Name="BewerkingId" Type="Int32" /> 
            <asp:Parameter Name="UserId" Type="Int32" /> 
            <asp:Parameter Name="ReadyDate" Type="DateTime" /> 
            <asp:Parameter Name="TaskDescription" Type="String" /> 
            <asp:Parameter Name="Remarks" Type="String" /> 
            <asp:Parameter Name="Date" Type="DateTime" /> 
            <asp:Parameter Name="StartDate" Type="DateTime" /> 
            <asp:Parameter Name="EstimatedHours" Type="Int32" /> 
            <asp:Parameter Name="RealHours" Type="Int32" /> 
            <asp:Parameter Name="NumberArticles" Type="Int64" /> 
            <asp:Parameter Name="EstimatedReadyDate" Type="DateTime" /> 
            <asp:Parameter Name="Status_actief" Type="String" /> 
            <asp:Parameter Name="StatusId" /> 
            <asp:Parameter Name="DateSendDataSteward" Type="DateTime" /> 
        </InsertParameters> 
    </asp:SqlDataSource> 
    <asp:SqlDataSource ID="dsStatus" runat="server" ConnectionString="<%$ ConnectionStrings:dsBewerkingenConnectionString %>" 
        SelectCommand="SELECT [StatusId], [StatusNam] FROM [tblStatusTasks]">  
        <SelectParameters> 
        </SelectParameters> 
    </asp:SqlDataSource> 
    <asp:SqlDataSource ID="dsFiles" runat="server" ConnectionString="<%$ ConnectionStrings:dsBewerkingenConnectionString %>" 
        SelectCommand="SELECT tblFiles.FileName, tblFiles.ProjectId, tblFiles.FileSaveAs, tblTasks.TaskId, tblFiles.FileId FROM tblFiles LEFT OUTER JOIN FilesPerTask ON tblFiles.FileId = FilesPerTask.FileId LEFT OUTER JOIN tblTasks ON FilesPerTask.TaskId = tblTasks.TaskId AND tblFiles.ProjectId = tblTasks.ProjectId WHERE (tblTasks.TaskId = @TaskId)">  
        <SelectParameters> 
            <asp:ControlParameter ControlID="gvTasksDataSteward" DefaultValue="0" Name="TaskId" 
                PropertyName="Selectedvalue" Type="Int32" /> 
        </SelectParameters> 
    </asp:SqlDataSource> 
</asp:Content> 

the VB
 
Partial Class ovz_Datasteward  
    Inherits System.Web.UI.Page  
    Private Function getItemName(ByVal tableName As StringAs String 
        Select Case tableName  
            Case ("DatastewardTasks")  
                Return "DatastewardTasks" 
            Case ("Details")  
                Return "Details" 
            Case Else 
                Return "" 
        End Select 
    End Function 
 
    Protected Sub gvDetails_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gvDetails.ItemCommand  
        If (e.CommandName = "RowClick" AndAlso (e.Item.OwnerTableView.DataSourceID = "dsFiles")) Then 
            If (TypeOf e.Item Is GridDataItem) Then 
                e.Item.Selected = True 
 
                Dim text As String = "Selected File Id is: " & e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("FileId")  
                Dim file As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("FileSaveAs")  
                Dim filename As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("FileName")  
 
                Dim ObjSR As FileStream  
                Dim path As String = System.Configuration.ConfigurationManager.AppSettings("UploadFolder").ToString  
                Dim fileToDownload As String = path + file  
 
                ObjSR = New FileStream(fileToDownload, FileMode.Open, FileAccess.Read)  
                Dim loc_StreamBuffer(ObjSR.Length) As Byte 
                ObjSR.Read(loc_StreamBuffer, 0, ObjSR.Length)  
                ObjSR.Close()  
                Response.AddHeader("content-disposition""attachment; filename=" & filename)  
                Response.BinaryWrite(loc_StreamBuffer)  
                Response.AppendHeader("Content-Length", loc_StreamBuffer.Length.ToString())  
                Response.End()  
            End If 
        End If 
    End Sub 
 
 
 
 
    'Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
    '    If Page.IsPostBack = True Then  
    '    End If  
    'End Sub  
 
 
    Protected Sub gvTasksDataSteward_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gvTasksDataSteward.ItemCommand  
        Dim cmdName As String = e.CommandName  
 
        If cmdName = "Executed" Then 
            Dim Today As Date = Now  
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)  
            Dim TaskId As Integer = dataItem("TaskId").Text  
            Dim strSQL As String = _  
                "UPDATE tblTasks " & _  
                "SET " & _  
            "StatusId =  @StatusId, " & _  
            "ReadyDate = @ReadyDate " & _  
                "WHERE TaskId = @TaskId " 
 
            Dim Command As New SqlCommand(strSQL)  
            Command.Parameters.Add(New SqlParameter("@StatusId", SqlDbType.Int)).Value = "5" 
            Command.Parameters.Add(New SqlParameter("@TaskId", SqlDbType.Int)).Value = TaskId  
            Command.Parameters.Add(New SqlParameter("@ReadyDate", SqlDbType.DateTime)).Value = Today  
            DBPortal.Execute(Command)  
 
        Else 
            If cmdName = "NotAccepted" Then 
                Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)  
                Dim TaskId As Integer = dataItem("TaskId").Text  
                Dim strSQL As String = _  
                    "UPDATE tblTasks " & _  
                    "SET " & _  
                "StatusId =  @StatusId " & _  
                    "WHERE TaskId = @TaskId " 
 
                Dim Command As New SqlCommand(strSQL)  
                Command.Parameters.Add(New SqlParameter("@StatusId", SqlDbType.Int)).Value = "3" 
                Command.Parameters.Add(New SqlParameter("@TaskId", SqlDbType.Int)).Value = TaskId  
                DBPortal.Execute(Command)  
            Else 
                If cmdName = "Accepted" Then 
                    Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)  
                    Dim TaskId As Integer = dataItem("TaskId").Text  
                    Dim strSQL As String = _  
                        "UPDATE tblTasks " & _  
                        "SET " & _  
                    "StatusId =  @StatusId " & _  
                        "WHERE TaskId = @TaskId " 
 
                    Dim Command As New SqlCommand(strSQL)  
                    Command.Parameters.Add(New SqlParameter("@StatusId", SqlDbType.Int)).Value = "4" 
                    Command.Parameters.Add(New SqlParameter("@TaskId", SqlDbType.Int)).Value = TaskId  
                    DBPortal.Execute(Command)  
                End If 
            End If 
        End If 
 
        If cmdName = RadGrid.EditCommandName Then 
 
 
        End If 
 
 
        gvTasksDataSteward.Rebind()  
    End Sub 
 
 
 
    Protected Sub gvTasksDataSteward_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles gvTasksDataSteward.PreRender  
        For Each dataItem As GridDataItem In gvTasksDataSteward.Items  
            'toont 'accepted' en 'not accepted' en verbergt 'Executed' indien Status 'Scheduled' is  
            If dataItem("StatusId").Text = "7" Then 
                Dim Accept As Button = DirectCast(dataItem("Accept").Controls(0), Button)  
                Dim NotAccept As Button = DirectCast(dataItem("NotAccept").Controls(0), Button)  
                Dim Executed As Button = DirectCast(dataItem("Executed").Controls(0), Button)  
                Accept.Visible = True 
                NotAccept.Visible = True 
                Executed.Visible = False 
            End If 
 
            'toont 'Executed' en verbergt  'accepted' en 'not accepted' indien Status 'Scheduled' is  
            If dataItem("StatusId").Text = "4" Then 
                Dim Accept As Button = DirectCast(dataItem("Accept").Controls(0), Button)  
                Dim NotAccept As Button = DirectCast(dataItem("NotAccept").Controls(0), Button)  
                Dim Executed As Button = DirectCast(dataItem("Executed").Controls(0), Button)  
                Accept.Visible = False 
                NotAccept.Visible = False 
                Executed.Visible = True 
            End If 
 
        Next 
 
          
    End Sub 
 
End Class 
 

2 Answers, 1 is accepted

Sort by
0
Mydatafactory
Top achievements
Rank 1
answered on 15 Jul 2009, 09:39 AM
After a refreshing break I decide to delete the 'gvTasksDataSteward.Rebind() ' in 'gvTasksDataSteward_ItemCommand'. Now the rowclick in the mastergrid gives the wright values in the detailsgrid.

However, I does the mastergrid rebind after clicking one of the buttons (Accept, Not Accept, Executed)
0
Sebastian
Telerik team
answered on 20 Jul 2009, 02:29 PM
Hello A.,

Can you please verify that you configured the master/detail grids in your scenario in conjunction with the concepts explained in these support resources:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectedvalue/defaultcs.aspx
http://www.telerik.com/help/aspnet-ajax/grdrelatedgrids.html

This should ensure that the grids will be refreshed without extra rebind calls. Additionally, test in Sql Management Studio that the query for the detail grid returns the proper set of results and whether the same scenario works with regular MS GridView instances attached to the SqlDataSource controls.

Finally, in case you ajaxify the grids via RadAjaxManager, verify that the second grid is specified as an updated control through the ajax setting which marks the first grid as initiator of the async request.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Mydatafactory
Top achievements
Rank 1
Answers by
Mydatafactory
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or