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

RadGrid disappears on Add New

2 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 28 Nov 2012, 05:25 PM
I have a very basic grid with the ability to add records directly to it.  When you click Add Record, you get a blank grid until a postback.  If you click the foo button, you'll see the grid comes back in add mode.  I tried adding an RadAjaxPanel and a RadAjaxManager, but neither fixed the issue. 

Help!

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <script type="text/javascript">
         
    </script>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="cartgrdItems">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="cartgrdItems" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
 
    </telerik:RadAjaxManager>
    <div>
    <telerik:RadAjaxPanel runat="server" ID="foo" EnableAJAX="true" ViewStateMode="Enabled">
        <telerik:RadGrid runat="server" ID="cartgrdItems">
            <MasterTableView EnableNoRecordsTemplate="true" CommandItemDisplay="Top" EditMode="InPlace">
                <CommandItemSettings ShowAddNewRecordButton="true" AddNewRecordText="Add Item" />               
            </MasterTableView>                   
        </telerik:RadGrid>
        <telerik:RadButton runat="server" ID="bar" text="foo" onclick="bar_Click" />   
        </telerik:RadAjaxPanel>
    </div>
    </form>
</body>
</html>


using System;
using System.Collections.Generic;
using System.Web.UI;
 
public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            List<ApprovalDetail> foo = new List<ApprovalDetail>();
            cartgrdItems.DataSource = new Object[0];
 
 
            cartgrdItems.DataSource = foo;
            cartgrdItems.DataBind();
        }
    }
 
    protected void bar_Click(object sender, EventArgs e)
    {
 
    }
     
    [Serializable]
    public class ApprovalDetail
    {
        public string PRNumber { get; set; }
        public int ItemNumber { get; set; }
        public string ItemNumberCode { get; set; }       
        public string ItemUOM { get; set; }
        public decimal ItemUnit { get; set; }
        public string ItemMatGroup { get; set; }
    }
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 29 Nov 2012, 04:23 AM
Hello,

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <script type="text/javascript">
          
    </script>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="cartgrdItems">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="cartgrdItems" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
  
    </telerik:RadAjaxManager>
    <div>
    <telerik:RadAjaxPanel runat="server" ID="foo" EnableAJAX="true" ViewStateMode="Enabled">
        <telerik:RadGrid runat="server" ID="cartgrdItems" OnNeedDataSource="RadGrid1_NeedDataSource">
            <MasterTableView EnableNoRecordsTemplate="true" CommandItemDisplay="Top" EditMode="InPlace">
                <CommandItemSettings ShowAddNewRecordButton="true" AddNewRecordText="Add Item" />              
            </MasterTableView>                  
        </telerik:RadGrid>
        <telerik:RadButton runat="server" ID="bar" text="foo" onclick="bar_Click" />  
        </telerik:RadAjaxPanel>
    </div>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Web.UI;
  
public partial class Default : System.Web.UI.Page
{
 
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
       List<ApprovalDetail> foo = new List<ApprovalDetail>();
            cartgrdItems.DataSource = new Object[0];
  
  
            cartgrdItems.DataSource = foo;
       
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
         
    }
  
    protected void bar_Click(object sender, EventArgs e)
    {
  
    }
      
    [Serializable]
    public class ApprovalDetail
    {
        public string PRNumber { get; set; }
        public int ItemNumber { get; set; }
        public string ItemNumberCode { get; set; }      
        public string ItemUOM { get; set; }
        public decimal ItemUnit { get; set; }
        public string ItemMatGroup { get; set; }
    }
}


Thanks,
Jayesh Goyani
0
Steven
Top achievements
Rank 1
answered on 29 Nov 2012, 03:15 PM
Yep, that did it.  Easy fix.
Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Steven
Top achievements
Rank 1
Share this question
or