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

Add row to an ajaxified RadGrid does not update the grid

2 Answers 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Coax
Top achievements
Rank 1
Coax asked on 12 Nov 2012, 10:52 PM
Hi,
I have a radgrid which on one of its ItemCommands, it adds a new row to the database, rebinds to the grid.
When I use normal postback it works fine, but the ajaxified version does not work. 
I've looked at the http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-not-refreshing-after-ajax-and-rebind.aspx which was not much of help for me.

Here is the aspx file:

<telerik:RadScriptManager runat="server" ID="radScriptManager1" />

<telerik:RadGrid    runat="server"
                                ID="radGrid1" 
                                AutoGenerateColumns="False"
                                EnableViewState="True"
                                OnItemCreated="radGrid1_OnItemCreated"
                                OnItemCommand="radGrid1_OnItemCommand"
                                OnNeedDataSource="lnkCopyGrade_OnNeedDataSource">
                <MasterTableView AllowFilteringByColumn="False" CommandItemDisplay="None" ClientDataKeyNames="grade_id">
                    <SortExpressions>
                        <telerik:GridSortExpression FieldName="grade_name" SortOrder="Ascending"/>
                    </SortExpressions>
                    <SortExpressions>
                        <telerik:GridSortExpression FieldName="sort_order" SortOrder="Ascending"/>
                    </SortExpressions>
                
                    <Columns>
                        <telerik:GridTemplateColumn HeaderText="" AllowFiltering="False">
                            <ItemTemplate>
                                <asp:ImageButton runat="server" ID="lnkCopyGrade" AlternateText="Copy Grade"
                                                CommandArgument='<%# DataBinder.Eval(Container.DataItem,"grade_id") %>' 
                                                CommandName="copyGrade" ImageUrl="../../../images/icons/CopyIconSmall24x24.png" ToolTip="Copy Grade"/>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn    HeaderText="Full Name" DataField="grade_name" 
                                                    AllowSorting="True" AllowFiltering="False"/>
                        <telerik:GridBoundColumn HeaderText="Sort<br>Order" DataField="sort_order" ItemStyle-HorizontalAlign="Center" AllowSorting="True" AllowFiltering="False"/>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
        
	<telerik:RadAjaxManager ID="ajaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="radGrid1" EventName="OnItemCommand">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="radGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>

And here is the relevant codebehind 


	protected void radGrid1_OnItemCommand(object sender, GridCommandEventArgs e)
	    {
	        int iGradeID = RVConversion.ToInt32(e.CommandArgument);
	        string sGradeName = radGrid1.Items[e.Item.ItemIndex].Cells[(intCOLS.NAME].Text;
 
            	string sURL;
            	switch (e.CommandName)
            		{
                		case "copyGrade":
                    			CopyGrade(iGradeID);
                    		break;
            		}
	    }
 	private void CopyGrade(int gradeID)
	    {
            	//rv_copy_grade
            	var arrParams = new RVParamArrayList();
            	arrParams.addInt32Param("@gradeID", gradeID);
 
            	var result = RVDB.execCommand("rv_copy_grade", arrParams);
           	 radGrid1.Rebind();
	    }
	 protected void lnkCopyGrade_OnNeedDataSource(object sender, GridNeedDataSourceEventArgs e)
	    {
            	object o = null;
            	IRVPageData_Base_GetData(ref o, new object[] { Entity.EntityID, null });
            	var ds = (GradeDataSet)o;
 
            	DataTable table = ds.Tables[0];
 
            	const string sAccessColumnName = "access";
            	table.Columns.Add(sAccessColumnName, Type.GetType("System.Int32"));
            	RVUserMisc.AddGradeSecurityToTable(table, sAccessColumnName, this);
            	var dv = new DataView(table);
            	radGrid1.DataSource = dv;
	    }
Worth saying that at the end of
lnkCopyGrade_OnNeedDataSource database is getting updated but from the console window of the browser I can see that following exception is thrown : Uncaught Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '<!DOCTYPE html PUBLI'. Telerik.Web.UI.WebResource.axd:6
Error.create Telerik.Web.UI.WebResource.axd:6
Sys.WebForms.PageRequestManager._createPageRequestManagerParserError Telerik.Web.UI.WebResource.axd:15
Sys.WebForms.PageRequestManager._parseDelta Telerik.Web.UI.WebResource.axd:15
Sys.WebForms.PageRequestManager._onFormSubmitCompleted Telerik.Web.UI.WebResource.axd:15
(anonymous function) Telerik.Web.UI.WebResource.axd:6
(anonymous function) Telerik.Web.UI.WebResource.axd:6
Sys.Net.WebRequest.completed Telerik.Web.UI.WebResource.axd:6
_onReadyStateChange Telerik.Web.UI.WebResource.axd:6


Thanks.

2 Answers, 1 is accepted

Sort by
0
Coax
Top achievements
Rank 1
answered on 13 Nov 2012, 11:48 PM
No one with any clue on this?
0
Angel Petrov
Telerik team
answered on 15 Nov 2012, 04:08 PM
Hello Coax,

This error usually reproduces when a control is not being ajaxified correctly. Could you please remove the RadAjaxManager and wrap the RadGrid in RadAjaxPanel. Sometimes setting EventName in the ajax settings for the ajax initiator control does not work. Give the upper-mentioned approach a try and let us know if the problem still persists. If it does, please open a formal support ticket with a project attached so we could investigate more thoroughly.

All the best,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Coax
Top achievements
Rank 1
Answers by
Coax
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or