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

JS error when no rows exist on postback

1 Answer 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hosney
Top achievements
Rank 1
Hosney asked on 10 Aug 2012, 09:02 AM
I get the following error when I remove all rows from the grid source and rebind the grid.

Error: 'this.get_element().tBodies.0.rows' is null or not an object

This does not happen in IE7. It happened to me in IE8 and Firefox.

ASPX:
<form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager" runat="server"></telerik:RadScriptManager>
    <telerik:RadAjaxPanel ID="RadAjaxPanel" runat="server">
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True"
            OnNeedDataSource="RadGrid1_NeedDataSource">
            <MasterTableView AutoGenerateColumns="True" ClientDataKeyNames="Id" DataKeyNames="Id" CommandItemDisplay="Top">
            </MasterTableView>
            <ClientSettings>
                <Selecting AllowRowSelect="True"></Selecting>
                <Scrolling AllowScroll="True" UseStaticHeaders="True"></Scrolling>
            </ClientSettings>
        </telerik:RadGrid>
        <telerik:RadButton ID="RadButton1" runat="server" Text="RadButton"
            onclick="RadButton1_Click">
        </telerik:RadButton>
    </telerik:RadAjaxPanel>
    </form>

C#:

private Dictionary<int, string> GridSource
{
   get
   {
       return (Dictionary<int, string>) ViewState["gridSource"];
   }
   set
   {
       ViewState["gridSource"] = value;
   }
}
protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
       GridSource = new Dictionary<int, string>();
 
       for (int i=0; i<2; i++)
       {
           GridSource.Add(i, "test data " + i);
       }
   }
}
 
protected void RadButton1_Click(object sender, EventArgs e)
{
   GridSource.Remove(int.Parse(RadGrid1.SelectedItems[0].Cells[2].Text));
   RadGrid1.Rebind();
}
 
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
   RadGrid1.DataSource = from d in GridSource select new { Id = d.Key, Text = d.Value };
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Leonard
Top achievements
Rank 1
answered on 15 Aug 2012, 04:19 AM
Solution from the Telerik team:

protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    var dataSource = from d in GridSource select new { Id = d.Key, Text = d.Value };
    RadGrid1.DataSource = dataSource.ToList();
}
Tags
Grid
Asked by
Hosney
Top achievements
Rank 1
Answers by
Leonard
Top achievements
Rank 1
Share this question
or