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

Hierarchical Grid - Can't Get to Work

4 Answers 21 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sasha
Top achievements
Rank 1
Sasha asked on 24 Sep 2013, 12:00 AM
Hello,
I am trying to follow the tutorial at http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/threelevel/defaultcs.aspx
Below is the applicable code as to where I think the issue may be. Anyone have any ideas why the grid does not even display any data when I load the page.

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGridSmears">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGridSmears"></telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
 
 
<telerik:RadGrid ID="RadGridSmears" runat="server" CellSpacing="0"
    DataSourceID="SqlDataSourceSmears" ShowStatusBar="True"
    AutoGenerateColumns="False" PageSize="3" AllowSorting="True"
    AllowPaging="True" GridLines="None" AllowAutomaticDeletes="True"
    AllowAutomaticUpdates="True" OnItemUpdated="RadGridSmears_ItemUpdated"
    OnItemDeleted="RadGridSmears_ItemDeleted">
 
    <PagerStyle Mode="NumericPages"></PagerStyle>
    <MasterTableView DataSourceID="SqlDataSourceSmears" DataKeyNames="SampleNo" AllowMultiColumnSorting="True"
        Width="100%" CommandItemDisplay="Top" Name="Smears">
        <DetailTables>
            <telerik:GridTableView DataKeyNames="AnalysisNo"
                DataSourceID="SqlDataSourceAnalysis" Width="100%"
                runat="server" CommandItemDisplay="Top" Name="Analysis">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="SampleNo" MasterKeyField="SampleNo">
                    </telerik:GridRelationFields>
                </ParentTableRelation>
...blah...blah
 
<asp:SqlDataSource ID="SqlDataSourceAnalysis" runat="server" ConnectionString="<%$ ConnectionStrings:XConnectionString %>"
    DeleteCommand="DELETE FROM [Analysis] WHERE [AnalysisNo] = @AnalysisNo AND [AnalysisDateTime]=@AnalysisDateTime"
    SelectCommand="SELECT * FROM [Analysis] WHERE [SampleNo] = @SampleNo" UpdateCommand="UPDATE [Analysis] SET [AnalysisDateTime] = @AnalysisDateTime, [AlphaCPM] = @AlphaCPM, [BetaCPM] = @BetaCPM, [InstrumentIDAlpha] = @InstrumentIDAlpha WHERE [AnalysisNo] = @AnalysisNo">
     <SelectParameters>
        <asp:Parameter Name="SampleNo" Type="String"></asp:Parameter>
    </SelectParameters>
    <DeleteParameters>
        <asp:Parameter Name="AnalysisNo" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="AnalysisDateTime" Type="DateTime"></asp:Parameter>
    </DeleteParameters>
    <UpdateParameters>
        <asp:Parameter Name="AnalysisDateTime" Type="DateTime"></asp:Parameter>
        <asp:Parameter Name="AlphaCPM" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="BetaCPM" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="InstrumentIDAlpha" Type="String"></asp:Parameter>
        <asp:Parameter Name="AnalysisNo" Type="Int32"></asp:Parameter>
    </UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceSmears" runat="server" ConnectionString="<%$ ConnectionStrings:XConnectionString %>"
    DeleteCommand="DELETE FROM [Smears] WHERE [SampleNo] = @SampleNo"
    SelectCommand="SELECT * FROM [Smears] WHERE [SampleNo] = @SampleNo" UpdateCommand="UPDATE [Smears] SET [Station] = @Station, [SampleDate] = @SampleDate, [BagNo] = @BagNo WHERE [SampleNo] = @SampleNo">
    <SelectParameters>
        <asp:Parameter Name="SampleNo" Type="String"></asp:Parameter>
    </SelectParameters>
    <DeleteParameters>
        <asp:Parameter Name="SampleNo" Type="String"></asp:Parameter>
    </DeleteParameters>
    <UpdateParameters>
        <asp:Parameter Name="Station" Type="String"></asp:Parameter>
        <asp:Parameter Name="SampleDate" Type="DateTime"></asp:Parameter>
        <asp:Parameter Name="BagNo" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="SampleNo" Type="String"></asp:Parameter>
    </UpdateParameters>
</asp:SqlDataSource>

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 24 Sep 2013, 06:04 AM
Hi Sasha,

Please correct you Connection code as below.

ASPX:
<asp:SqlDataSource ID="SqlDataSourceSmears" runat="server" ConnectionString="<%$ ConnectionStrings:XConnectionString %>"
    DeleteCommand="DELETE FROM [Smears] WHERE [SampleNo] = @SampleNo" SelectCommand="SELECT * FROM [Smears]"
    UpdateCommand="UPDATE [Smears] SET [Station] = @Station, [SampleDate] = @SampleDate, [BagNo] = @BagNo WHERE [SampleNo] = @SampleNo">
    <DeleteParameters>
        <asp:Parameter Name="SampleNo" Type="String"></asp:Parameter>
    </DeleteParameters>
    <UpdateParameters>
        <asp:Parameter Name="Station" Type="String"></asp:Parameter>
        <asp:Parameter Name="SampleDate" Type="DateTime"></asp:Parameter>
        <asp:Parameter Name="BagNo" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="SampleNo" Type="String"></asp:Parameter>
    </UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceAnalysis" runat="server" ConnectionString="<%$ ConnectionStrings:XConnectionString %>"
    DeleteCommand="DELETE FROM [Analysis] WHERE [AnalysisNo] = @AnalysisNo AND [AnalysisDateTime]=@AnalysisDateTime"
    SelectCommand="SELECT * FROM [Analysis] WHERE [SampleNo] = @SampleNo" UpdateCommand="UPDATE [Analysis] SET [AnalysisDateTime] = @AnalysisDateTime, [AlphaCPM] = @AlphaCPM, [BetaCPM] = @BetaCPM, [InstrumentIDAlpha] = @InstrumentIDAlpha WHERE [AnalysisNo] = @AnalysisNo">
    <SelectParameters>
        <asp:Parameter Name="SampleNo" Type="String"></asp:Parameter>
    </SelectParameters>
    <DeleteParameters>
        <asp:Parameter Name="AnalysisNo" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="AnalysisDateTime" Type="DateTime"></asp:Parameter>
    </DeleteParameters>
    <UpdateParameters>
        <asp:Parameter Name="AnalysisDateTime" Type="DateTime"></asp:Parameter>
        <asp:Parameter Name="AlphaCPM" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="BetaCPM" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="InstrumentIDAlpha" Type="String"></asp:Parameter>
        <asp:Parameter Name="AnalysisNo" Type="Int32"></asp:Parameter>
    </UpdateParameters>
</asp:SqlDataSource>

Thanks,
Princy
0
Sasha
Top achievements
Rank 1
answered on 24 Sep 2013, 09:37 AM
Grid now displays...thanks.
However, I am finding the child row does not indent nicely like the demo when I click on the parent row.
The first column called SampleNo column in both the parent and child row are aligned vertically but I was hoping to have the column in the child row indented somewhat like the demo.
Any ideas?
0
Sasha
Top achievements
Rank 1
answered on 24 Sep 2013, 10:04 AM
Perhaps it is not possible as looking closer at the demo...the first parent-child drilldown does indent but there are 3 tables in total while I only have 2. The order-product relationship does not indent like the first parent-child drilldown in the demo  similar to how mine functions. Please confirm.
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/threelevel/defaultcs.aspx
0
Princy
Top achievements
Rank 1
answered on 25 Sep 2013, 07:08 AM
Hi Sasha,

You can add a GridExpandColumn to achieve your required scenario.Please try the following code snippet

ASPX:
<telerik:RadGrid ID="RadGridSmears" runat="server"  OnItemDataBound="RadGridSmears_ItemDataBound" . . >
    <MasterTableView >
        <DetailTables>
            <telerik:GridTableView Name="Analysis" . . .>
                <ParentTableRelation>
                    <telerik:GridRelationFields . . ></telerik:GridRelationFields>
                </ParentTableRelation>
                <Columns>
                    <telerik:GridExpandColumn UniqueName="Expand">
                    </telerik:GridExpandColumn>
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGridSmears_ItemDataBound(object sender, GridItemEventArgs e)
   {
       //To hide the Expand/Collapse Button
       if (e.Item.OwnerTableView.Name == "Analysis")
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem item = (GridDataItem)e.Item;
               TableCell cell = item["Expand"];
               cell.Controls[0].Visible = false;            
           }
       }
   }

Thanks,
Princy
Tags
Grid
Asked by
Sasha
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Sasha
Top achievements
Rank 1
Share this question
or