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

RadGrid1_ItemCreated prevent RadGrid to expand row details

5 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 05 Dec 2013, 01:22 PM
Hello,

I developed my project in Visual Studio 2013 and my project have a RadGrid with DetailTables inside to able to expand row details. Then I follow demo sample


to add a RadWindow for Edit and Add New Record.

All working fine until I added a RadGrid1_ItemCreated code behind to create dynamic URL for Edit link button

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink");
                editLink.Attributes["href"] = "javascript:void(0);";
                editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}','{2}','{3}');",
                    e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmpID"],
                    e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["RowID"],
                    e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["VoucherID"],
                    e.Item.ItemIndex);
            }
        }

I could not expand row details anymore.  I get an error in Chrome browser console:
Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object. Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=rsm_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSys…:6
Error.create Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=rsm_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSys…:6
Sys.WebForms.PageRequestManager._createPageRequestManagerServerError Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=rsm_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSys…:15
Sys.WebForms.PageRequestManager._parseDelta Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=rsm_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSys…:15
Sys.WebForms.PageRequestManager._onFormSubmitCompleted Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=rsm_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSys…:15
(anonymous function) Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=rsm_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSys…:6
(anonymous function) Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=rsm_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSys…:6
Sys.Net.WebRequest.completed Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=rsm_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSys…:6
_onReadyStateChange Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=rsm_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSys…:6

As soon as I took OnItemCreated="RadGrid1_ItemCreated", the expand row works again

Can anyone please look at it?  I don't know if this issue cause by Visual Studio 2013

Thanks,
Sam

5 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 06 Dec 2013, 08:51 AM
Hi Sam,

Please use the property Name for the Parent and Child Grid so as to Identify the Tables separately.Please try the following code snippet:

ASPX:
<MasterTableView  Name="Parent" . . . >
 <telerik:GridTableView Name="Child". . .>

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
 {
    if (e.Item is GridDataItem)
    {
        if (e.Item.OwnerTableView.Name == "Parent")
        {
          HyperLink editLink1 = (HyperLink)e.Item.FindControl("EditLink1");
            //Your Code
        }
        else if (e.Item.OwnerTableView.Name == "Child")
        {
           HyperLink editLink2 = (HyperLink)e.Item.FindControl("EditLink2");          
           //Your code
        }
    }       
 }

Thanks,
Princy
0
Sam
Top achievements
Rank 1
answered on 06 Dec 2013, 02:37 PM
Hello,

I added property Name for the Parent and Child for the Grid
<telerik:RadGrid ID="RadGrid1" EnableEmbeddedSkins="true" runat="server" AllowPaging="True"
                    AutoGenerateDeleteColumn="False" AutoGenerateEditColumn="False" CellSpacing="0" GridLines="Both"
                    AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
                    OnPreRender="RadGrid1_PreRender" OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnItemCreated="RadGrid1_ItemCreated">
 
                    <MasterTableView Name="Parent" DataKeyNames="EmpID,VoucherID,RowID">                       
                        <DetailTables>
                            <telerik:GridTableView Name="Child" AutoGenerateColumns="false" DataKeyNames="EmpID,RowID,VoucherID" HierarchyLoadMode="ServerOnDemand">
                                <ColumnGroups>
                                    <telerik:GridColumnGroup HeaderText="Time" Name="Time" HeaderStyle-HorizontalAlign="Center">
                                    </telerik:GridColumnGroup>
                                    <telerik:GridColumnGroup HeaderText="Odometer" Name="Odometer" HeaderStyle-HorizontalAlign="Center">
                                    </telerik:GridColumnGroup>
                                </ColumnGroups>
                                <Columns>
                                    <telerik:GridBoundColumn DataField="TimeDeparted" HeaderText="Departed" ColumnGroupName="Time"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="TimeArrived" HeaderText="Arrived" ColumnGroupName="Time"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="OdometerBegin" HeaderText="Begin" ColumnGroupName="Odometer"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="OdometerEnd" HeaderText="End" ColumnGroupName="Odometer"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="DOTMiles" HeaderText="DOT Miles"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="MileageAdjustment" HeaderText="Mileage<br />Adjustment"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Tolls" HeaderText="Tolls"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Others" HeaderText="Others"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Fund" HeaderText="Fund"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="CostCenter" HeaderText="Cost Center"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Account" HeaderText="Account"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Project" HeaderText="Project"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Task" HeaderText="Task"></telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="ExpOrg" HeaderText="Exp Org"></telerik:GridBoundColumn>
                                </Columns>
                            </telerik:GridTableView>
                        </DetailTables>
                        <ColumnGroups>
                            <telerik:GridColumnGroup HeaderText="Location" Name="Location" HeaderStyle-HorizontalAlign="Center">
                            </telerik:GridColumnGroup>
                        </ColumnGroups>
                        <Columns>
                            <telerik:GridBoundColumn DataField="Date" FilterControlAltText="Filter Date column" HeaderText="Date" SortExpression="Date" UniqueName="Date" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Activity" FilterControlAltText="Filter Activity column" HeaderText="Activity" SortExpression="Activity" UniqueName="Activity">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="LocationFrom" FilterControlAltText="Filter LocationFrom column" HeaderText="From" SortExpression="LocationFrom" UniqueName="LocationFrom" ColumnGroupName="Location">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="LocationTo" FilterControlAltText="Filter LocationTo column" HeaderText="To" SortExpression="LocationTo" UniqueName="LocationTo" ColumnGroupName="Location">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="NetMiles" DataType="System.Decimal" FilterControlAltText="Filter NetMiles column" HeaderText="Net Miles" SortExpression="NetMiles" UniqueName="NetMiles">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Amount" DataType="System.Decimal" FilterControlAltText="Filter Amount column" HeaderText="Amount" SortExpression="Amount" UniqueName="Amount">
                            </telerik:GridBoundColumn>
                            <telerik:GridButtonColumn ConfirmText="Delete this product?" ButtonType="PushButton"
                                CommandName="Delete" Text="Delete" UniqueName="DeleteColumn1">
                                <HeaderStyle Width="20px"></HeaderStyle>
                                <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
                            </telerik:GridButtonColumn>
                            <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
                                <ItemTemplate>
                                    <asp:HyperLink runat="server" ID="EditLink" Text="Edit"></asp:HyperLink>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                    </MasterTableView>
 
                    <HeaderContextMenu EnableEmbeddedSkins="False"></HeaderContextMenu>
                </telerik:RadGrid>

and code behind for the OnItemCreaded
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                if (e.Item.OwnerTableView.Name == "Parent")
                {
                    HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink");
                    editLink.Attributes["href"] = "javascript:void(0);";
                    editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}','{2}','{3}');",
                        e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmpID"],
                        e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["RowID"],
                        e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["VoucherID"],
                        e.Item.ItemIndex);
                }
                else if (e.Item.OwnerTableView.Name == "Child")
                {
                    // nothing
                }
            }
        }

The RadWindow on Edit Link and the rows expand for the RadGrid are working, but when I click on a row to expand, I get this error on Firefox's console (Firebug):
SyntaxError: An invalid or illegal string was specified
}if(e[c].indexOf("{")!=-1){f.insertRule(e[c]+"}",f.cssRules.length);

http://localhost:53600/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=rsm_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bTelerik.Web.UI%2c+Version%3d2013.3.1114.40%2c+Culture%3dneutral%2c+PublicKeyToken%3d121fae78165ba3d4%3aen-US%3a8d3dfe81-f887-4a80-ad14-8e882b52e5e6%3a16e4e7cd%3aed16cbdc%3af7645509%3a88144a7a%3ab7778d6c%3a24ee1bba%3a7165f74%3a1e771326%3af46195d3%3a6b3f73b3%3a8674cba1%3a7c926187%3ac08e9f8a%3a58366029%3a92fe8ea0%3afa31b949%3a874f8ea2%3a19620875%3a490a9d4e%3abd8f85e4%3aa51ee93e%3a59462f1
Line 1578


Thanks for your help,
Sam
0
Viktor Tachev
Telerik team
answered on 10 Dec 2013, 01:57 PM
Hello Sam,

I tried replicating the error, however I was unable to. I am attaching a sample project that I used for testing. Would you give it a try and let me know what is different in your scenario?

Regards,
Viktor Tachev
Telerik
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 the blog feed now.
0
Sam
Top achievements
Rank 1
answered on 11 Dec 2013, 03:18 AM
Hi Viktor,

I downloaded your sample and unzipped.  
  1. Opened the extracted folder in Visual Studio 2013 via File->Open Website...
  2. imported Telerik.Web.UI.dll and Telerik.Web.UI.Skins.dll
  3. Run without debug in Visual Studio 2013
  4. click expand the first row.  I get window error popup.

Please see attachment for the screenshot error in IE 11 (other versions get same error, too)

Thanks for your help,
Sam
0
Accepted
Viktor Tachev
Telerik team
answered on 13 Dec 2013, 03:51 PM
Hello Sam,

In order to avoid this error you need to disable the Browser Link feature in Visual Studio. I would also recommend taking a look at this thread where the issue is described.

Regards,
Viktor Tachev
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Sam
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sam
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or