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

Error when expanding a NestedViewTable in RadGrid when a row is selected

1 Answer 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 07 Mar 2014, 06:52 PM
Error when expanding a NestedViewTable in RadGrid when a row is selected and HierarchyLoadMethod is ServerOnDemand.

I have a RadGrid with a NestedViewTable.  HierarchyLoadMethod is set to "ServerOnDemand".  I can expand the NestedViewTable just fine unless I first select a row.  The error message is within a Telerik JS file and reads: "Input string was not in acorrect format."  This works when I set the HierachyLoadMethod to "ServerBind" however this takes way too long.   It appears to be a Telerik issue to me.   Please provide guidance on how I can solve this problems.  Thank you.

-Steve

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Mar 2014, 05:41 AM
Hi Stephen,

I'm not able to replicate such an issue at my end. Below is a sample code snippet that I tried and works fine at my end. Please take a look and provide your code snippet if this doesn't help.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="true" OnItemCommand="RadGrid1_ItemCommand">
    <MasterTableView DataKeyNames="CustomerID" Name="Parent" CommandItemDisplay="Top" HierarchyLoadMode="ServerOnDemand">
        <NestedViewTemplate>
            <telerik:RadGrid ID="RadGrid2" runat="server" OnNeedDataSource="RadGrid2_NeedDataSource" MasterTableView-Name="Child" AutoGenerateColumns="false">
                <MasterTableView>
                    <Columns>
                        <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID" />
                        <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" UniqueName="CustomerID" />
                    </Columns>
                </MasterTableView>
                <ClientSettings Selecting-AllowRowSelect="true">
                </ClientSettings>
            </telerik:RadGrid>
        </NestedViewTemplate>
    </MasterTableView>
    <ClientSettings AllowExpandCollapse="true" Selecting-AllowRowSelect="true">
    </ClientSettings>
</telerik:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = GetDataTable("SELECT CustomerID, CompanyName, ContactTitle FROM Customers");
}
protected void RadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    GridDataItem parentItem = ((sender as RadGrid).NamingContainer as GridNestedViewItem).ParentItem as GridDataItem;
    (sender as RadGrid).DataSource = GetDataTable("SELECT OrderID, EmployeeID, CustomerID FROM Orders where CustomerID='" + parentItem.GetDataKeyValue("CustomerID").ToString() + "'");
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExpandCollapseCommandName && !e.Item.Expanded)
    {
        GridDataItem parentItem = e.Item as GridDataItem;
        RadGrid grid = parentItem.ChildItem.FindControl("RadGrid2") as RadGrid;
        grid.Rebind();
    }
}
public DataTable GetDataTable(string query)
{
    String ConnString = ConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
    SqlConnection conn = new SqlConnection(ConnString);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand(query, conn);
    DataTable myDataTable = new DataTable();
    conn.Open();
    try
    {
        adapter.Fill(myDataTable);
    }
    finally
    {
        conn.Close();
    }
    return myDataTable;
}

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