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

Error on add new record or on edit

3 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sampada
Top achievements
Rank 1
Sampada asked on 27 Jun 2012, 10:13 AM

Telerik Team,

I am using telerik grid in my application.

When the filter for the grid is shown on when I check the display filter checkbox and I click on Add New Record  or Edit the Record then I get the following error stated below.

Line: 6

Error: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.

My code is as below

<body>
    <form id="form1" runat="server">
     <telerik:RadScriptManager ID="ScriptManager" runat="server" />
       <fieldset class="configureFieldsetClass">
                                <legend>Grid</legend>
                                    
                                  <table class="configureTableClass">
                                    <tr>
                                        <td align="right">
                                            <asp:CheckBox ID="CheckBox1" Text="Display Filter" runat="server" OnCheckedChanged="displayfilter_checkchanged"
                                                AutoPostBack="true" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <telerik:RadGrid ID="dgGrid" runat="server" AllowSorting="True" FilterItemStyle-HorizontalAlign="Center"
                                                AllowFilteringByColumn="false" AllowPaging="true" PageSize="10" AutoGenerateColumns="false"
                                                AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
                                                OnNeedDataSource="dgGrid_NeedDataSource" OnInsertCommand="dgGrid_ItemInserted"
                                                OnUpdateCommand="dgGrid_ItemInserted" OnDeleteCommand="dgGrid_ItemInserted">
                                                <GroupHeaderItemStyle></GroupHeaderItemStyle>
                                                <FilterMenu>
                                                </FilterMenu>
                                                <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" />
                                                <MasterTableView BorderWidth="0" ShowFooter="False" EditMode="InPlace" GridLines="Both"
                                                    Font-Names="Arial" CommandItemDisplay="top" AutoGenerateColumns="false" InsertItemDisplay="Bottom"
                                                    DataKeyNames="PARAM_GRID_ITEM_ID" CommandItemSettings-ShowRefreshButton="false"
                                                    CommandItemSettings-AddNewRecordText="Add New Record">
                                                    <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" />
                                                    <RowIndicatorColumn Visible="False" UniqueName="RowIndicator">
                                                        <HeaderStyle></HeaderStyle>
                                                        <ItemStyle></ItemStyle>
                                                    </RowIndicatorColumn>
                                                    <Columns>
                                                        <telerik:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="Images/Edit.jpg"
                                                            ItemStyle-Wrap="true" HeaderStyle-Width="8%">
                                                        </telerik:GridEditCommandColumn>
                                                        <telerik:GridBoundColumn UniqueName="COLUMN_NAME" SortExpression="COLUMN_NAME" HeaderText="Column"
                                                            DataField="COLUMN_NAME" DataType="System.String" HeaderStyle-Width="20%">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn UniqueName="CAPTION_NAME" SortExpression="CAPTION_NAME" HeaderText="Caption"
                                                            DataField="CAPTION_NAME" DataType="System.String" HeaderStyle-Width="25%">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridNumericColumn UniqueName="COLUMN_ORDER" SortExpression="COLUMN_ORDER" HeaderText="Column Order"
                                                            DataField="COLUMN_ORDER" HeaderStyle-Width="23%">
                                                        </telerik:GridNumericColumn>
                                                        <telerik:GridDropDownColumn HeaderText="Data Type" UniqueName="PARAM_TYPE_ID" DataField="PARAM_TYPE_ID"
                                                            ListTextField="PARAM_TYPE" ListValueField="PARAM_TYPE_ID" DataSourceID="DsDataType"
                                                            SortExpression="PARAM_TYPE_ID" HeaderStyle-Width="20%">
                                                        </telerik:GridDropDownColumn>
                                                        <telerik:GridBoundColumn UniqueName="PARAM_GRID_ID" SortExpression="PARAM_GRID_ID" HeaderText="PARAM_GRID_ID"
                                                            DataField="PARAM_GRID_ID" DataType="System.String" Display="false" HeaderStyle-Width="1%">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn UniqueName="PARAM_GRID_ITEM_ID" SortExpression="PARAM_GRID_ITEM_ID"
                                                            HeaderText="PARAM_GRID_ITEM_ID" DataField="PARAM_GRID_ITEM_ID" DataType="System.String"
                                                            Display="false" HeaderStyle-Width="1%">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                                                            ItemStyle-HorizontalAlign="Center" UniqueName="DeleteColumn" HeaderStyle-Width="5%"
                                                            ConfirmText="Confirm that you want to delete the record?" ImageUrl="Images/Delete1.gif"
                                                            ConfirmTitle="Delete ?">
                                                        </telerik:GridButtonColumn>
                                                    </Columns>
                                                    <EditFormSettings>
                                                        <EditColumn ButtonType="ImageButton" HeaderStyle-Width="50px" />
                                                    </EditFormSettings>
                                                </MasterTableView>
                                                <HeaderStyle></HeaderStyle>
                                                <SelectedItemStyle></SelectedItemStyle>
                                                <ItemStyle VerticalAlign="Top"></ItemStyle>
                                                <FooterStyle></FooterStyle>
                                                <HeaderStyle HorizontalAlign="Center" />
                                                <ClientSettings EnableRowHoverStyle="true">
                                                    <ClientEvents OnRowMouseOver="RowMouseOver" OnCommand="OnCommand" OnRowMouseOut="RowMouseOut" />
                                                    <Selecting AllowRowSelect="True"></Selecting>
                                                    <Resizing AllowRowResize="true" EnableRealTimeResize="false" ResizeGridOnColumnResize="false"
                                                        AllowColumnResize="false"></Resizing>
                                                </ClientSettings>
                                            </telerik:RadGrid>
                                        </td>
                                    </tr>
                                </table>
                              
                            </fieldset>
    </form>
</body>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using eControls;
using System.Data;
using eDataAccess;
using SRSBO;
using eBusinessObjects;
using System.Text.RegularExpressions;
 
public partial class Demo : System.Web.UI.Page
{
    public int NodeId = -1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!(int.TryParse(Request.QueryString["NODEID"], out NodeId)))
        {
            NodeId = -1;
        }
        
    }
 
    public void displayfilter_checkchanged(object s, EventArgs e)
    {
        if (CheckBox1.Checked)
        {
            dgGrid.MasterTableView.AllowFilteringByColumn = true;
 
        }
        else
        {
            dgGrid.MasterTableView.AllowFilteringByColumn = false;
 
        }
        dgGrid.GroupingSettings.CaseSensitive = false;
 
        dgGrid.Rebind();
 
 
    }
 
    protected void dgGrid_ItemInserted(object source, GridCommandEventArgs e)
    {
 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            ConfigureParamBO objConfigureParamBO = new ConfigureParamBO();
                       
            ParamGridItemBO pgiBO = new ParamGridItemBO();
            ParamGridBO objParamGridBO = new ParamGridBO();
            DataTable dtGridDataId = objParamGridBO.GetGridDataIdForNodeId();
            if (dtGridDataId.Rows.Count == 0)
            {
                Boolean isSuccess = SaveGridData();
                if (isSuccess)
                {
                   
                }
            }
            dtGridDataId = objParamGridBO.GetGridDataIdForNodeId(Convert.ToInt32(hidNodeId.Value));
             
            ParamGridBO pgBO = new ParamGridBO();
            Dictionary<string, object> Adds = new Dictionary<string, object>();
            Adds.Add("PARAM_GRID_ID", hidParamGridId.Value.ToString());
            
            dgGrid.InsertGridRecords(source, e, pgiBO, Adds);
           
            dgGrid.Rebind();
        }
    }
 
    protected void dgGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
 
        ParamGridItemBO pgiBO = new ParamGridItemBO();
        dgGrid.DataSource = pgiBO.getDgGridDataSource(NodeId);
    }
 
    
 
}

A demo source code would be of great help.

Can you please let me know the work around for it?

Thanking you in advance.

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 27 Jun 2012, 01:57 PM
Hello,

I am not able to reproduce the issue please check below code snippet.


<telerik:RadGrid ID="dgGrid" runat="server" AllowSorting="True" FilterItemStyle-HorizontalAlign="Center"
           AllowFilteringByColumn="false" AllowPaging="true" PageSize="10" AutoGenerateColumns="false"
           AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
           OnNeedDataSource="dgGrid_NeedDataSource" OnInsertCommand="dgGrid_ItemInserted">
           <GroupHeaderItemStyle></GroupHeaderItemStyle>
           <FilterMenu>
           </FilterMenu>
           <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" />
           <MasterTableView BorderWidth="0" ShowFooter="False" EditMode="InPlace" GridLines="Both"
               Font-Names="Arial" CommandItemDisplay="top" AutoGenerateColumns="false" InsertItemDisplay="Bottom"
               CommandItemSettings-ShowRefreshButton="false" CommandItemSettings-AddNewRecordText="Add New Record">
               <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" />
               <RowIndicatorColumn Visible="False" UniqueName="RowIndicator">
                   <HeaderStyle></HeaderStyle>
                   <ItemStyle></ItemStyle>
               </RowIndicatorColumn>
               <Columns>
                   <telerik:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="Images/Edit.jpg"
                       ItemStyle-Wrap="true" HeaderStyle-Width="8%">
                   </telerik:GridEditCommandColumn>
                   <telerik:GridBoundColumn UniqueName="Name" SortExpression="Name" HeaderText="Name"
                       DataField="Name" DataType="System.String">
                   </telerik:GridBoundColumn>
               </Columns>
               <EditFormSettings>
                   <EditColumn ButtonType="ImageButton" HeaderStyle-Width="50px" />
               </EditFormSettings>
           </MasterTableView>
           <HeaderStyle></HeaderStyle>
           <SelectedItemStyle></SelectedItemStyle>
           <ItemStyle VerticalAlign="Top"></ItemStyle>
           <FooterStyle></FooterStyle>
           <HeaderStyle HorizontalAlign="Center" />
           <ClientSettings EnableRowHoverStyle="true">
               <Selecting AllowRowSelect="True"></Selecting>
               <Resizing AllowRowResize="true" EnableRealTimeResize="false" ResizeGridOnColumnResize="false"
                   AllowColumnResize="false"></Resizing>
           </ClientSettings>
       </telerik:RadGrid>
protected void dgGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
  {
      dynamic data = new[] {
              new { ID = 2, Name ="Name2"},
              new { ID = 2, Name = "Name2"},
              new { ID = 2, Name = "Name2"}
          };
      dgGrid.DataSource = data;
  }
 
  public void displayfilter_checkchanged(object s, EventArgs e)
  {
      if (CheckBox1.Checked)
      {
          dgGrid.MasterTableView.AllowFilteringByColumn = true;
 
      }
      else
      {
          dgGrid.MasterTableView.AllowFilteringByColumn = false;
 
      }
      dgGrid.GroupingSettings.CaseSensitive = false;
 
      dgGrid.Rebind();
 
  }
 
  protected void dgGrid_ItemInserted(object source, GridCommandEventArgs e)
  {
 
      if (e.Item is GridEditableItem && e.Item.IsInEditMode)
      {
          //ConfigureParamBO objConfigureParamBO = new ConfigureParamBO();
 
          //ParamGridItemBO pgiBO = new ParamGridItemBO();
          //ParamGridBO objParamGridBO = new ParamGridBO();
          //DataTable dtGridDataId = objParamGridBO.GetGridDataIdForNodeId();
          //if (dtGridDataId.Rows.Count == 0)
          //{
          //    Boolean isSuccess = SaveGridData();
          //    if (isSuccess)
          //    {
 
          //    }
          //}
          //dtGridDataId = objParamGridBO.GetGridDataIdForNodeId(Convert.ToInt32(hidNodeId.Value));
 
          //ParamGridBO pgBO = new ParamGridBO();
          //Dictionary<string, object> Adds = new Dictionary<string, object>();
          //Adds.Add("PARAM_GRID_ID", hidParamGridId.Value.ToString());
 
          //dgGrid.InsertGridRecords(source, e, pgiBO, Adds);
 
          dgGrid.Rebind();
           
      }
  }


Thanks,
Jayesh Goyani
0
Sampada
Top achievements
Rank 1
answered on 29 Jun 2012, 05:04 AM
Thanks for reply...

Can you please use this code with telerik:GridDropDownColumn 

Whenever I remove telerik:GridDropDownColumn from the code every thing works fine.

As soon as I add telerik:GridDropDownColumn  it start giving me above mentioned error.



0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Jun 2012, 05:36 AM
Hello,

I have checked with DropDownColumn but not able to reproduce.
<telerik:RadGrid ID="dgGrid" runat="server" AllowSorting="True" FilterItemStyle-HorizontalAlign="Center"
           AllowFilteringByColumn="false" AllowPaging="true" PageSize="10" AutoGenerateColumns="false"
           AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
           OnNeedDataSource="dgGrid_NeedDataSource" OnInsertCommand="dgGrid_ItemInserted">
           <GroupHeaderItemStyle></GroupHeaderItemStyle>
           <FilterMenu>
           </FilterMenu>
           <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" />
           <MasterTableView BorderWidth="0" ShowFooter="False" EditMode="InPlace" GridLines="Both"
               Font-Names="Arial" CommandItemDisplay="top" AutoGenerateColumns="false" InsertItemDisplay="Bottom"
               CommandItemSettings-ShowRefreshButton="false" CommandItemSettings-AddNewRecordText="Add New Record">
               <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" />
               <RowIndicatorColumn Visible="False" UniqueName="RowIndicator">
                   <HeaderStyle></HeaderStyle>
                   <ItemStyle></ItemStyle>
               </RowIndicatorColumn>
               <Columns>
                   <telerik:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="Images/Edit.jpg"
                       ItemStyle-Wrap="true" HeaderStyle-Width="8%">
                   </telerik:GridEditCommandColumn>
                   <telerik:GridBoundColumn UniqueName="Name" SortExpression="Name" HeaderText="Name"
                       DataField="Name" DataType="System.String">
                   </telerik:GridBoundColumn>
 
                   <telerik:GridDropDownColumn HeaderText="Data Type" UniqueName="PARAM_TYPE_ID" DataField="Name"
                       SortExpression="Name" HeaderStyle-Width="20%"
                        DataSourceID="SqlDataSource1"
                         ListTextField="ContactName" ListValueField="CustomerID">
                   </telerik:GridDropDownColumn>
               </Columns>
               <EditFormSettings>
                   <EditColumn ButtonType="ImageButton" HeaderStyle-Width="50px" />
               </EditFormSettings>
           </MasterTableView>
           <HeaderStyle></HeaderStyle>
           <SelectedItemStyle></SelectedItemStyle>
           <ItemStyle VerticalAlign="Top"></ItemStyle>
           <FooterStyle></FooterStyle>
           <HeaderStyle HorizontalAlign="Center" />
           <ClientSettings EnableRowHoverStyle="true">
               <Selecting AllowRowSelect="True"></Selecting>
               <Resizing AllowRowResize="true" EnableRealTimeResize="false" ResizeGridOnColumnResize="false"
                   AllowColumnResize="false"></Resizing>
           </ClientSettings>
       </telerik:RadGrid>
       <asp:SqlDataSource ID="SqlDataSource1" runat="server"
           ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
           SelectCommand="SELECT [CustomerID], [ContactName] FROM [Contacts]"></asp:SqlDataSource>

Note : if you are not able to resolved the problem then try to assign datasource in ItemDataSource event.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Sampada
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Sampada
Top achievements
Rank 1
Share this question
or