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

[Solved] Problem With RadGrid with ObjectDataSource

4 Answers 378 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Forest
Top achievements
Rank 1
Forest asked on 16 Apr 2009, 06:48 PM
The issue is I have some dropdownlists on the grid that map to enumerations.  In each one of these drop down lists, the first choice is always blank - nothing there at all. 

I'm using an objectdatasource with this.

When I use inplace editing or the form that's built for me using template columns, I can select blank and udpate the database with null - not a problem.

However, when I try to use the Template edit mode, I get an error raised in the RaisePostbackEvent method.  It complains that cannot convert a string (the blank in the dropdownlist) to the enumerated type. 

This is going on in the objectdatasource I know, but I'm asking here because you guys seem to be solving this issue someway in non-template editing form mode, or maybe I'm missing something ??? 

Side note: The business object that's being bound exposes 4 different types of enumerated datatypes. They're all nullable types.  I also have logic in the set accessor to handle empty string data that comes in.  However, it appears the ObjectDataSource is doing its own thing creating the object and not using my set accessors. 

Wondering if it's possible to actually grab the business object itself before it creates it and change the fields.  I was able to extract it the objectdatasource's updating event, but that fires after it's already created. 

It's annoying and I dont' understand why it doesn't work in template edit mode. 

Here's the grid: 

 

<telerik:RadGrid ID="RadGrid1"  BorderWidth="0px" runat="server" DataSourceID="odsRules"   
            AllowSorting="True" AllowAutomaticInserts="True" PageSize="10"   
            GridLines="Vertical" AllowAutomaticDeletes="True"   
            AllowAutomaticUpdates="True" Skin="Vista"   
            AutoGenerateColumns="False" onitemdatabound="RadGrid1_ItemDataBound"   
            AllowPaging="True" oninsertcommand="RadGrid1_InsertCommand"   
            onitemcommand="RadGrid1_ItemCommand" oniteminserted="RadGrid1_ItemInserted">  
          
        <MasterTableView DataSourceID="odsRules" CommandItemDisplay="TopAndBottom" DataKeyNames="RuleID, EstimateFormID" Width="900px">   
            <Columns> 
                <telerik:GridEditCommandColumn ButtonType="ImageButton" /> 
                <telerik:GridBoundColumn DataField="RuleID" Visible="False" ReadOnly="true" /> 
                  
                <telerik:GridTemplateColumn DataField="EstimateFormID" Visible="false">  
                    <ItemTemplate> 
                        <asp:Label id="lblEstimateFormID" runat="server" Text='<%# Bind("EstimateFormID") %>'></asp:Label> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                  
                <telerik:GridTemplateColumn HeaderText="Activity Number" SortExpression="ActivityNumber">  
                    <EditItemTemplate> 
                        <asp:TextBox id="txtActivityNumber" runat="server" Text='<%# Bind("ActivityNumber") %>'></asp:TextBox> 
                    </EditItemTemplate> 
                    <ItemTemplate> 
                        <asp:Label id="lblActivityNumber" runat="server" Text='<%# Bind("ActivityNumber") %>'></asp:Label> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                  
                <telerik:GridTemplateColumn HeaderText="Abbreviation" SortExpression="Abbreviation">  
                    <EditItemTemplate> 
                        <uc1:AbbreviationList SelectedValue='<%# Bind("Abbreviation") %>' ID="ddlAbbreviation" runat="server" /> 
                    </EditItemTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="Label1" runat="server" Text='<%# GetValue(DataBinder.Eval(Container.DataItem, "Abbreviation")) %>'></asp:Label> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                  
                <telerik:GridTemplateColumn HeaderText="Discipline" SortExpression="Discipline">  
                    <EditItemTemplate> 
                        <uc1:DisciplineList SelectedValue='<%# Bind("Discipline") %>' ID="ddlDiscipline" runat="server" /> 
                    </EditItemTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblDiscipline" runat="server" Text='<%# GetValue(DataBinder.Eval(Container.DataItem, "Discipline")) %>'></asp:Label> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                  
                <telerik:GridTemplateColumn HeaderText="Resource" EditFormColumnIndex="1" SortExpression="Resource">  
                    <EditItemTemplate> 
                        <uc1:ResourceList SelectedValue='<%# Bind("Resource") %>' ID="ddlResource" runat="server" />   
                    </EditItemTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblResource" runat="server" Text='<%# GetValue(DataBinder.Eval(Container.DataItem, "Resource")) %>'></asp:Label> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn>   
                  
                <telerik:GridTemplateColumn HeaderText="Time" EditFormColumnIndex="1" SortExpression="Time">  
                    <EditItemTemplate> 
                        <uc1:TimeList id="timeList" SelectedValue='<%# Bind("Time") %>' runat="server"></uc1:TimeList> 
                    </EditItemTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblTime" runat="server" Text='<%# GetValue(DataBinder.Eval(Container.DataItem, "Time")) %>'></asp:Label> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                  
                <telerik:GridTemplateColumn HeaderText="Hard Factor" EditFormColumnIndex="1">   
                    <ItemTemplate> 
                        <asp:Label ID="lblHardFactor" runat="server" Text='<%# Bind("HardFactor") %>'></asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:TextBox ID="txtHardFactor" runat="server" Text='<%# Bind("HardFactor") %>'></asp:TextBox> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn>   
                <telerik:GridButtonColumn ConfirmText="Delete this rule?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />       
 
            </Columns>   
 
        <EditFormSettings EditFormType="AutoGenerated" ColumnNumber="2"  CaptionFormatString="Edit properties of Hard Factor Rule.">  
            <EditColumn ButtonType="ImageButton" UpdateImageUrl="http://demos.telerik.com/aspnet/Grid/Examples/DataEditing/AllEditableColumns/Img/save.gif" EditImageUrl="..\Img\Edit.gif" 
                        InsertImageUrl="http://demos.telerik.com/aspnet/Grid/Examples/DataEditing/AllEditableColumns/Img/save.gif" CancelImageUrl="http://demos.telerik.com/aspnet/Grid/Examples/DataEditing/AllEditableColumns/Img/cancel.gif" InsertText="Insert rule" 
                        UpdateText="Update rule" UniqueName="EditCommandColumn1" CancelText="Cancel rule">  
            </EditColumn> 
              
    
            <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" /> 
            <FormMainTableStyle Width="100%" GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White" /> 
            <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle> 
              
    
            <FormTableItemStyle Wrap="False"></FormTableItemStyle> 
            <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> 
            <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle> 
            <FormTemplate> 
                <span class="EditFormHeader">Edit properties of Hard Factor Rule.</span>==><asp:Label id="lblEditEstimateFormID" runat="server" Text='<%# Bind("EstimateFormID") %>'></asp:Label> 
    
                <br /><br />   
                <table style="width: 900px;">  
                    <tr> 
                        <td style="width:12%;">Activity Number:</td><td><asp:TextBox id="txtActivityNumber" runat="server" Text='<%# Bind("ActivityNumber") %>'></asp:TextBox></td>  
                        <td style="width:12%;">Resource:</td><td><uc1:ResourceList SelectedValue='<%# Bind("Resource") %>' ID="ddlResource" runat="server" /></td>  
                    </tr> 
                    <tr> 
                        <td style="width:12%;">Abbreviation:</td><td><uc1:AbbreviationList SelectedValue='<%# Bind("Abbreviation") %>' ID="ddlAbbreviation" runat="server" /></td>  
                        <td style="width:12%;">Time:</td><td><uc1:TimeList id="timeList" SelectedValue='<%# Bind("Time") %>' runat="server"></uc1:TimeList></td>  
                    </tr> 
                    <tr> 
                        <td style="width:12%;">Discipline:</td><td><uc1:DisciplineList SelectedValue='<%# Bind("Discipline") %>' ID="ddlDiscipline" runat="server" /></td>  
                        <td style="width:12%;">Hard Factor:</td><td><asp:TextBox ID="lblHardFactor" runat="server" Text='<%# Bind("HardFactor") %>'></asp:TextBox></td>  
                    </tr> 
                    <tr> 
                        <td></td><td></td><td></td>  
                        <td align="left">  
                            <asp:ImageButton ID="btnUpdate" ImageUrl='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "http://demos.telerik.com/aspnet/Grid/Examples/DataEditing/AllEditableColumns/Img/save.gif" : "http://demos.telerik.com/aspnet/Grid/Examples/DataEditing/AllEditableColumns/Img/save.gif" %>' runat="server" CommandName='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "PerformInsert" : "Update" %>'></asp:ImageButton>&nbsp;  
                            <asp:ImageButton ID="btnCancel" ImageUrl="http://demos.telerik.com/aspnet/Grid/Examples/DataEditing/AllEditableColumns/Img/cancel.gif" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:ImageButton> 
                        </td> 
                    </tr> 
                </table>   
              
            </FormTemplate> 
        </EditFormSettings> 
     
        <HeaderStyle Width="20px"></HeaderStyle> 
     
        </MasterTableView> 
        <ClientSettings> 
            <Selecting AllowRowSelect="True" /> 
            <ClientEvents OnRowClick="RowClick" OnRowDblClick="RowDblClick" 
                          OnGridCreated="GridCreated" OnCommand="GridCommand" /> 
        </ClientSettings> 
    </telerik:RadGrid> 

 

 


And the exception: 

[InvalidOperationException: Cannot convert value of parameter 'Time' from 'System.String' to 'Turner.Quickplan.Enums.EstimateTimeType']
   System.Web.UI.WebControls.ObjectDataSourceView.ConvertType(Object value, Type type, String paramName) +378
   System.Web.UI.WebControls.ObjectDataSourceView.BuildObjectValue(Object value, Type destinationType, String paramName) +167
   System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type dataObjectType, IDictionary inputParameters) +214
   System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +462
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +92
   Telerik.Web.UI.GridTableView.PerformUpdate(GridEditableItem editedItem, Boolean suppressRebind) +224
   Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +975
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +134
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   Telerik.Web.UI.GridEditFormItem.OnBubbleEvent(Object source, EventArgs e) +299
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +111
   System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +176
   System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   Quickplan.HardFactorPage.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) in C:\QP3\Quickplan\Quickplan\HardFactorPage.aspx.cs:20
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

This happens on edits and inserts when ANY drop down list is blank .... 

Thanks in advace.
 

4 Answers, 1 is accepted

Sort by
0
Forest
Top achievements
Rank 1
answered on 17 Apr 2009, 02:40 PM
Bump.
0
Nikolay Rusev
Telerik team
answered on 22 Apr 2009, 09:00 AM
Hello Forest,

For your convenience I am sending you application which demonstrates one possible solution in scenario. Please find it attached to this post.

Kind regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marco Miccini
Top achievements
Rank 1
answered on 04 Oct 2009, 10:07 PM
Dear all,
I have tested the attached sample since I'm getting a problem updating a business object datasource using the RadGrid.
Unfortunately I get the same problem also within the sample you offered: if you change some values in Edit Mode and press Update, the changes are not committed. Why?
Also in my case the Select procedure is entered successfully to populate the data of the RadGrid but not the same for the Update and Delete procedures on my business object, even if using as parameters of these procedures the same name in the same order of the writable properties of the business object itself.
Instead of using the RadGrid, by using the normal GridView control with the same business object datasource the same Update procedure, this is entered successfully and the object really updated (truly speaking, the Delete procedure does not work also on the GridView).
Why this different behavior on your component?
Thanks,
Davide
0
Nikolay Rusev
Telerik team
answered on 07 Oct 2009, 10:30 AM
Hello Marco,

Below links explains how RadGrid works with DataSource controls:
http://www.telerik.com/help/aspnet-ajax/grdautomaticdatasourceoperations.html
http://www.telerik.com/community/code-library/submission/b311D-kemte.aspx

Sincerely yours,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Forest
Top achievements
Rank 1
Answers by
Forest
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Marco Miccini
Top achievements
Rank 1
Share this question
or