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

Problem inserting records in GridTableView - Please Help!

7 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 24 Jun 2011, 07:27 PM
I have been searching all morning for a demo or example of inserting a record into a child grid in a hierarchical grid to no avail. The odd thing is, that this was working at one point and I am not sure what changed.

It's a fairly simple grid. The problem I am having is that in the InsertCommand method when I extract the values I see the keys of the two columns I am looking for but the values are always null. Any insight as to what I am doing wrong would be greatly appreciated!

My grid:

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" CellSpacing="0" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCommand="ViewResponse"
    OnSortCommand="RadGrid1_SortCommand" OnPageIndexChanged="RadGrid1_PageIndexChanged" OnPageSizeChanged="RadGrid1_PageSizeChanged" Skin="Office2007"
    ShowStatusBar="true" Width="100%"  AllowSorting="True" AllowPaging="True" PageSize="20" OnNeedDataSource="GridNeedsDataSource" OnPreRender="RadGrid1_PreRender"
    OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnUpdateCommand="RadGrid1_UpdateCommand" OnInsertCommand="RadGrid1_InsertCommand" >
    <MasterTableView DataKeyNames="response_id, survey_id, email_sent_history_id" >                                    
        <DetailTables>
            <telerik:GridTableView DataKeyNames="email_sent_history_id" Name="Calls" Width="100%" runat="server" CommandItemDisplay="Top">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="email_sent_history_id" MasterKeyField="email_sent_history_id" />
                </ParentTableRelation>
                <Columns>
                    <telerik:GridDateTimeColumn HeaderText="Call Date" DataField="call_date" UniqueName="call_date" PickerType="DatePicker">
                    </telerik:GridDateTimeColumn>
                    <telerik:GridBoundColumn HeaderText="Call Outcome" DataField="call_outcome" UniqueName="call_outcome">
                    </telerik:GridBoundColumn>
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>
            <telerik:GridBoundColumn DataField="email_sent_history_id" UniqueName="ResponseId" Visible="false" />
            <telerik:GridBoundColumn DataField="response_id" UniqueName="ResponseId" Visible="false" />
            <telerik:GridBoundColumn UniqueName="first_name" DataField="first_name" HeaderText="First Name" />                                        
            <telerik:GridBoundColumn  DataField="last_name" HeaderText="Last Name" />                                        
            <telerik:GridBoundColumn  DataField="organization" HeaderText="Organization" />
            <telerik:GridBoundColumn  DataField="pi_name" Headertext="PI Name" />
            <telerik:GridBoundColumn  DataField="response_date" DataFormatString="{0:MM/dd/yyyy}"  Headertext="Response Date" />
            <telerik:GridBoundColumn  DataField="current_status" HeaderText="Survey Status" />                                       
            <telerik:GridBoundColumn  DataField="score" Headertext="Score" />
            <telerik:GridButtonColumn UniqueName="Response" Text="View" HeaderText="Response" CommandName="ViewResponse"/>                                     
            <telerik:GridBoundColumn  DataField="feasibility_status" HeaderText="feasibility_status" />                                                                                     
        </Columns>                      
        <PagerStyle AlwaysVisible="True" Mode="NextPrevAndNumeric" Position="TopAndBottom"></PagerStyle>
    </MasterTableView>
    <ClientSettings>
        <Selecting AllowRowSelect="true" />
    </ClientSettings>
</telerik:RadGrid>

My insertcommand method
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
        {
            GridEditFormInsertItem item = e.Item as GridEditFormInsertItem;
            if (item == null)
            {
                return;
            }
 
            string errorString = string.Empty;
            Hashtable values = new Hashtable();
            item.ExtractValues(values);
            try
            {
                var callDate = values["call_date"] == null ? string.Empty : values["call_date"].ToString();
                var callOutcome = values["call_outcome"] == null ? string.Empty : values["call_outcome"].ToString();
 
                /*Do some error checking and update the DB if we have values. callDate and callOutcome are always an empty string!*/
                 
            }
            catch (Exception ex)
            {
 
                RadGrid1.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", ex.Message)));
                e.Canceled = true;
            }
        }

I put a comment in place of where I am actually doing to the insert into the db because I figured it wasn't relevant. When I view the values HashTable in debug mode, after extracting the values. I can see that it has the two datakeys: call_date and call_outcome, but the values are always null....

thanks for any help!

7 Answers, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 1
answered on 28 Jun 2011, 03:12 PM
Can someone maybe even point me to a working demo?
0
Tim
Top achievements
Rank 1
answered on 28 Jun 2011, 04:34 PM
anyone?
0
Iana Tsolova
Telerik team
answered on 29 Jun 2011, 11:29 AM
Hello Tim,

Reviewing your code I suggest that you remove the ParentTableRelation definition as it is necessary only in case you have declarative binding for the grid. Other than this I cannot find any reason for the unexpected behavior.
Check it out and let me know if it makes any difference.

Best wishes,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Tim
Top achievements
Rank 1
answered on 29 Jun 2011, 02:26 PM
Thank you for the response. I actually have already tried removing the parentRelation, and in fact when this was working I did not have that parentRelation in there, I just put it in as I was trying to figure out why this stopped working.

I have seen some posts on the forums that mention you should not use bind/rebind when using hierarchical grids. I removed any explicit bind/rebind calls from my code to no avail. Any other ideas what could be going on here? The specific behavior I am seeing is that I click the add new record button. I enter some values into both fields and click insert which calls the onInsertCommand method. It appears that something is clearing out the values that I entered before the InsertCommand method is reached.

Do you have a working example that I could look at? The demo at http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/threelevel/defaultcs.aspx

does not seem to insert any records either.. ?

0
Iana Tsolova
Telerik team
answered on 30 Jun 2011, 07:59 AM
Hi Tim,

Below is demo illustrating CRUD operation with hierarchical grid, but it uses automatic operations.
And to be able to give other ideas, I will need to build a runnable sample simulating your case and issue. Can you send me the whole page code, or open a formal support ticket and attach a runnable version of your web site there?

Kind regards,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Tim
Top achievements
Rank 1
answered on 01 Jul 2011, 03:35 PM
Thanks again for the response.

Also I discovered something this morning. Everything works fine when I run my application in IE(8). I only seem to have this problem when I run the application in Firefox. Any thoughts?

Tim
0
Iana Tsolova
Telerik team
answered on 04 Jul 2011, 10:31 AM
Hi Tim,

The functionality and implementation of RadGrid CRUD operations is not browser dependable as it is done server-side. However, can you try changing the Update/Insert button type to PushButton (ASP:Button) and let me know how it goes?

If the issue persist, I would need to check the whole page code.

Greetings,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or