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

Syncronising Two Grids

2 Answers 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 07 Jul 2011, 12:16 AM
I have two grids on my page.

The user is to select a row from grid1 which will display details of that row in grid 2

My datasource for grid 2 is set to take the selected index from grid 1. Here is my code for the grids

Grid 1
<telerik:RadGrid ID="FileList" Width="97%"
             AllowPaging="True" runat="server" AllowSorting="True"
             OnNeedDataSource="FileList_NeedDataSource" GridLines="None"
                AutoGenerateColumns="False" Skin="Windows7" Height="220px">
<HeaderContextMenu EnableImageSprites="True" ></HeaderContextMenu>
 
              <MasterTableView Width="100%" DataKeyNames="FileID" >
<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
              <Columns>
        <telerik:GridBoundColumn DataField="FileID" DataType="System.Int32"
            HeaderText="FileID" SortExpression="FileID" UniqueName="FileID"
            ReadOnly="True" Visible="false">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="FileNumber" HeaderText="File Number"
            SortExpression="FileNumber" UniqueName="FileNumber"
            HeaderStyle-Width="85px" ItemStyle-HorizontalAlign="Center">
<HeaderStyle Width="85px"></HeaderStyle>
 
<ItemStyle HorizontalAlign="Center"></ItemStyle>
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="DateEntered" DataType="System.DateTime" DataFormatString="{0:dd/MM/yyyy}"
            HeaderText="Date Entered" SortExpression="DateEntered"
            UniqueName="DateEntered" HeaderStyle-Width="85px">
<HeaderStyle Width="85px"></HeaderStyle>
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="DateBoxed" DataType="System.DateTime" DataFormatString="{0:dd/MM/yyyy}"
            HeaderText="Date Boxed" SortExpression="DateBoxed" UniqueName="DateBoxed"
            HeaderStyle-Width="85px">
<HeaderStyle Width="85px"></HeaderStyle>
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="DestroyDate" DataType="System.DateTime" HeaderStyle-Width="100px"
            HeaderText="Destroy Date" ReadOnly="True" SortExpression="DestroyDate" DataFormatString="{0:dd/MM/yyyy}"
            UniqueName="DestroyDate">
<HeaderStyle Width="100px"></HeaderStyle>
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="FileStatus" HeaderText="File Status" HeaderStyle-Width="115px"
            SortExpression="FileStatus" UniqueName="FileStatus">
<HeaderStyle Width="115px"></HeaderStyle>
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Business" DataType="System.Int32"
            HeaderText="Business" SortExpression="Business" UniqueName="Business" Visible="false">
        </telerik:GridBoundColumn>
    </Columns></MasterTableView>
              <PagerStyle Mode="NextPrevAndNumeric" />
                <ClientSettings>
                    <Selecting AllowRowSelect="True"    />
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                     
                </ClientSettings>
                <FilterMenu EnableTheming="True" >
                    <CollapseAnimation Duration="200" Type="OutQuint" />
                </FilterMenu>
            </telerik:RadGrid>

Code behind for Grid 1
Protected Sub FileList_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles FileList.NeedDataSource
        FileList.DataSource = GetFileList
    End Sub

GetFileList Datasource
<asp:SqlDataSource ID="GetFileList" runat="server"
        ConnectionString="<%$ ConnectionStrings:FileawaySQLConnectionString %>"
        SelectCommand="SELECT * FROM [qryFileList] WHERE ([Business] = @Business)">
        <SelectParameters>
            <asp:ControlParameter ControlID="lblUserID" Name="Business"
                PropertyName="Text" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

Grid 2 (to display details from selected row in Grid 1)

<telerik:RadGrid ID="FileHistory" Width="97%"
             AllowPaging="True" runat="server" AllowSorting="True"
             OnNeedDataSource="FileHistory_NeedDataSource" GridLines="None"
                AutoGenerateColumns="False" Skin="Windows7" Height="220px">
<HeaderContextMenu EnableImageSprites="True" ></HeaderContextMenu>
 
              <MasterTableView Width="100%" >
<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
              <Columns>
        <telerik:GridBoundColumn DataField="FileID" DataType="System.Int32"
            HeaderText="FileID" ReadOnly="True" SortExpression="FileID" UniqueName="FileID">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="FileNumber" HeaderText="FileNumber"
            SortExpression="FileNumber" UniqueName="FileNumber">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="FileHistoryAction"
            HeaderText="FileHistoryAction" SortExpression="FileHistoryAction"
            UniqueName="FileHistoryAction">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="DateofAction" DataType="System.DateTime"
            HeaderText="DateofAction" SortExpression="DateofAction"
            UniqueName="DateofAction">
        </telerik:GridBoundColumn>
    </Columns></MasterTableView>
              <PagerStyle Mode="NextPrevAndNumeric" />
                <ClientSettings>
                    <Selecting AllowRowSelect="True"   />
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                     
                </ClientSettings>
                <FilterMenu EnableTheming="True" >
                    <CollapseAnimation Duration="200" Type="OutQuint" />
                </FilterMenu>
            </telerik:RadGrid>

Codebehind for Grid 2
Protected Sub FileHistory_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles FileHistory.NeedDataSource
        FileList.DataSource = GetFileHistory
    End Sub

GetFileHistory Datasource
<asp:SqlDataSource ID="GetFileHistory" runat="server"
        ConnectionString="<%$ ConnectionStrings:FileawaySQLConnectionString %>"
        SelectCommand="SELECT * FROM [qryFileHistory] WHERE ([FileID] = @FileID)">
        <SelectParameters>
            <asp:ControlParameter ControlID="FileList" Name="FileID"
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

Not sure why these are not linking. Do I need to specify additional postback code?

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Jul 2011, 06:00 AM
Hello Andrew,

Please take a look at the following demo which demonstrates the same.
Grid / Master/Detail Grids.

Thanks,
Shinu.
0
Andrew
Top achievements
Rank 1
answered on 07 Jul 2011, 07:52 AM
I have looked at they demo but that doesn't use needdatasource. So it won't allow me to use autopostback
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Andrew
Top achievements
Rank 1
Share this question
or