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

RadGrid, GridDropDownColumn and ObjectDataSource

1 Answer 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephane
Top achievements
Rank 1
Stephane asked on 11 Feb 2011, 10:24 PM
Hello,

I have a basic Grid composed with one GridDropDownColumn.

The grid is filled through ObjectdataSource1 :
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
           OldValuesParameterFormatString="original_{0}" OnSelecting="ObjectDataSource1_Selecting"
           SelectMethod="select_AllWeek" TypeName="Planning.WeekDAL" 
           DataObjectTypeName="Planning.Week" UpdateMethod="update_Week">
           <SelectParameters>
               <asp:Parameter Name="IdFrame" Type="Int32" />
           </SelectParameters>
       </asp:ObjectDataSource>

The SelectMethod returns a generic List of Week:
[DataObjectMethod(DataObjectMethodType.Select)]
       public static List<Week> select_AllWeek(int IdFrame)
       {...}


The DropDownColum is filled through ObjectDataSource2:
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" OldValuesParameterFormatString="original_{0}"
           SelectMethod="select_Alldays" TypeName="Planning.DayDAL"></asp:ObjectDataSource>

The SelectMethod returns a generic List of Day:
[DataObjectMethod(DataObjectMethodType.Select)]
        public static List<Day> select_AllDays()
        {
....}


The Grid is configured like that:
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AutoGenerateColumns="False"
            DataSourceID="ObjectDataSource1">
            <MasterTableView DataSourceID="ObjectDataSource1" EditMode="InPlace">
                <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                <RowIndicatorColumn>
                    <HeaderStyle Width="20px"></HeaderStyle>
                </RowIndicatorColumn>
                <ExpandCollapseColumn>
                    <HeaderStyle Width="20px"></HeaderStyle>
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" Groupable="False"
                        HeaderText="Week" UniqueName="Week" DataField="Libelle">
                    </telerik:GridBoundColumn>
                    <telerik:GridDropDownColumn DataSourceID="ObjectDataSource2" ListTextField="Code"
                        ListValueField="Id" DataField="Monday.Id" UniqueName="Monday" HeaderText="Monday"
                        FooterStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" AllowFiltering="False"
                        AllowSorting="False" Groupable="False">
                    </telerik:GridDropDownColumn>
                     <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" Groupable="False"
                        HeaderText="Tuesday" UniqueName="Tuesday" DataField="Tuesday.Code">
                    </telerik:GridBoundColumn>
                    <telerik:GridEditCommandColumn>
                    </telerik:GridEditCommandColumn>
                </Columns>
                <EditFormSettings>
                    <EditColumn UniqueName="EditCommandColumn1">
                    </EditColumn>
                </EditFormSettings>
            </MasterTableView>
            <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default">
            </HeaderContextMenu>
        </telerik:RadGrid>

The Week class is defined like that :
public class Week: IEnumerable
    {
  
        #region Fields
  
        protected List<Day> Days= new List<Day>();
  
        private int _id;
   ...

# region properties

     public Day Monday
        {
            get{return Days[0];}
            set{Days[0] = value;}
        }


and the Day class :

public class Day
    {
        #region Fields
  
        private int _id;
        private string _code;
       ...
#endregion
  
  
        #region Properties
  
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
  
        public string Code
        {
            get {return _code;}
            set  { _code = value;}
        }
...
]


The values are correctly displayed in both Grid and DropdownList. The problem is during the update phase.  

The Update method of the ObjectDataSource1 is defined like that:

[DataObjectMethod(DataObjectMethodType.Update)]
        public static void update_Week(Week oneweek)
        {
            PrepareConnexion();
            connexion.Open();
            ...


The selected value of the Dropdownlist  ("Code" property of the Day object) is not saved in the database. It seems there is "no link" between RadGrid and Dropdowlist controls. What is the best practise to link a GridDropDownColumn Value in a  RadGridView Using ObjectDataSource (one for Dropdownlist and one for Gridview) ?

Thanks for your support.

Regards,

Stephane


































































1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 16 Feb 2011, 09:15 AM
Hi Stephane,

This is probably because you use a nested property for the DataField of the GridDropDownColumn (DataField="Monday.Id"). When using nested properties, grid columns can successfully databind and display the data of the nested property. However, this is not true for data editing. RadGrid does not support automatic data operations with columns bound to nested properties. You will have to update your data source programmatically.

In fact, RadGrid does not have AllowAutomaticUpdates/AllowAutomaticInserts/AllowAutomaticDeletes set to true. This means the grid is not automatically updating any data values. In this case, no data should be automatically saved in the database.

Veli
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
Stephane
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or