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

Updating from RadDataForm using ObjectDataSource

1 Answer 197 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Rolland
Top achievements
Rank 1
Rolland asked on 02 Dec 2016, 07:39 PM

I've been trying to update the data in my RadDataForm for a long time now but without success. 

 

I am using an object called UtilisateurDetailViewModel (code below) and a class name UtilisateurDetailDataObject that takes care of doing the DB calls (CRUD) through a standard BLL-DAL etc. 

 

I bind my data to my form using a double click that calls the select method on ym ObjectDataSource using parameters. 

 

The problem I am facing is that watever I do, clicking my button with the CommandName="Update" in the EditItemTemplate doesn't do anything. I have tried tons of things to make it work but nothing. 

 

Here is all my code, hoping it's only a little mistake or an option that's missing. I know it is a big chunk of code, but the UtilisateurDetailViewModel and RadDataForm have a lot of repitition that doesn't need reading since it's just several radtextboxed for the values.

 

1. My UtilisateurDetailViewModel object

01.namespace CCQ.GestionSEL.Intranet.ZJWEB013.ViewModel
02.{
03.    public class UtilisateurDetailViewModel
04.    {
05.        private Utilisateur _utilisateur;
06.        private Compte _compte;
07. 
08.        public UtilisateurDetailViewModel(Utilisateur us_net, Compte ut_net)
09.        {
10.            if (us_net == null)
11.                throw new ArgumentNullException("us_net");
12. 
13.            if (ut_net == null)
14.                throw new ArgumentNullException("ut_net");
15. 
16.            _utilisateur = us_net;
17.            _compte = ut_net;
18.        }
19.        public string Type
20.        {
21.            get { return _utilisateur.TyUtilNet.Trim(); }
22.            set { _utilisateur.TyUtilNet = value; }
23.        }
24.        public string NumeroUtilisateur
25.        {
26.            get { return _utilisateur.IdentUtilNet.Trim() + "-" + _utilisateur.NoUsagerNet; }
27.            set { _utilisateur.IdentUtilNet = value; }
28.        }
29.        public string NomPrenom
30.        {
31.            set { _utilisateur.NomPrenom = value; }
32.            get { return _utilisateur.NomPrenom.Trim(); }
33.        }
34.        public string Courriel
35.        {
36.            get { if (_utilisateur.AdrCourriel != null) { return _utilisateur.AdrCourriel.Trim(); } else { return ""; }  }
37.            set { _utilisateur.AdrCourriel = value; }
38.        }
39.        public DateTime? DateCreation
40.        {
41.            get { return _utilisateur.DteCreer; }
42.            set { _utilisateur.DteCreer = value; }
43.        }
44.        public DateTime? DateModification
45.        {
46.            get { return _utilisateur.DteModif; }
47.            set { _utilisateur.DteModif = value; }
48.        }
49.        public DateTime? DateUtilisation
50.        {
51.            get { return _utilisateur.DteDernUtilisation; }
52.            set { _utilisateur.DteDernUtilisation = value; }
53.        }
54.        public string Principal
55.        {
56.            get { if (_utilisateur.EstUtilisateurPrincipal) { return "Oui"; } else { return "Non"; } }
57.        }
58.        public string Compte
59.        {
60.            get { return _compte.TyUtilNet + _compte.IdentUtilNet; }
61.        }
62.        public string Statut
63.        {
64.            get { if (_compte.statut == 1) { return "Actif"; } else { return "Inactif"; } }
65.            set { if (value == "Actif") { _compte.statut = 1; } else { _compte.statut = 0; }; }
66.        }
67.        public DateTime? DateStatut
68.        {
69.            get { if (_compte.statut == 1) { return _compte.DteCreer; } else { return _compte.DteInactif; } }
70.        }
71.        public string TypeCompte
72.        {
73.            get { return _utilisateur.NoUsagerNet.Trim() == "00" ? "Principal" : "Secondaire"; }
74.            set { if (value == "Principal") { _utilisateur.NoUsagerNet = "00"; } else { _utilisateur.NoUsagerNet = null; }  }
75.        }
76.    }

 

**************************************************************************************************************************************************************************************

2. My UtilisateurDetailDataObject (Contains CRUD logic)

01.namespace CCQ.GestionSEL.Intranet.ZJWEB013
02.{
03.    [DataObject]
04.    public class UtilisateurDetailDataObject
05.    {
06.        [DataObjectMethod(DataObjectMethodType.Select)]
07.        public UtilisateurDetailViewModel ObtenirUtilisateur(string type, string numeroUtilisateur)
08.        {
09.            string identUtil = "";
10.            string noUsager = "";
11.            string[] splitResult;
12. 
13.            if(type == null || numeroUtilisateur == null)
14.            {
15.                return null;
16.            }
17. 
18.            var listeUtilisateursVM = new List<UtilisateurDetailViewModel>();
19. 
20.            var bllUsNet = new ZJ.AuthentificationSEL.BLL.Utilisateur();
21.            var bllUtNet = new ZJ.AuthentificationSEL.BLL.Compte();
22.            if(numeroUtilisateur != null)
23.            {
24.                splitResult = numeroUtilisateur.Split('-');
25.                if (splitResult.Length > 1)
26.                {
27.                    identUtil = splitResult[0];
28.                    noUsager = splitResult[1];
29.                }
30.                else
31.                {
32.                    return null;
33.                }
34.            }
35.             
36.            Utilisateur utilisateur = bllUsNet.Obtenir(type, identUtil, noUsager);
37.            Compte compte = bllUtNet.Obtenir(utilisateur.TyUtilNet, utilisateur.IdentUtilNet);
38. 
39.            return new UtilisateurDetailViewModel(utilisateur, compte);
40.        }
41. 
42.        [DataObjectMethod(DataObjectMethodType.Update)]
43.        public void Update_DetailsUtilisateurs(UtilisateurDetailViewModel user)
44.        {
45.             
46.        }
47. 
48.        public void Insert(UtilisateurDetailViewModel user)
49.        {
50. 
51.        }
52.    }
53.}

 

**************************************************************************************************************************************************************************************

3. My ObjectDataSource

01.<asp:ObjectDataSource ID="SourceRadDataForm"
02.       runat="server"
03.       DataObjectTypeName="CCQ.GestionSEL.Intranet.ZJWEB013.ViewModel.UtilisateurDetailViewModel"
04.       SelectMethod="ObtenirUtilisateur"
05.       InsertMethod="asas"
06.       UpdateMethod="Update_DetailsUtilisateurs"
07.       TypeName="CCQ.GestionSEL.Intranet.ZJWEB013.UtilisateurDetailDataObject"
08.       OldValuesParameterFormatString="original_{0}">
09.       <SelectParameters>
10.           <asp:Parameter Name="type" Type="String" />
11.           <asp:Parameter Name="numeroUtilisateur" Type="String" />
12.       </SelectParameters>
13.   </asp:ObjectDataSource>

 

**************************************************************************************************************************************************************************************

4. My RadDataForm (contains the data that I bind from my UtilisateurDetailViewModel)

001.<telerik:RadDataForm ID="DetailDataForm"
002.                    runat="server"
003.                    DataSourceID="SourceRadDataForm"                   
004.                    DataKeyNames="Type,NumeroUtilisateur">
005.                    <LayoutTemplate>
006.                        <div id="itemPlaceholder" runat="server" visible="false"/>
007.                    </LayoutTemplate>
008.                    <ItemTemplate>
009.                        <fieldset class="form">
010.                            <div id="teteDroit">
011.                                <h2 class="DetailTitle">Utilisateur</h2>
012.                                <div class="inputwrap">
013.                                    <label for="Type">Type: </label>
014.                                    <telerik:RadTextBox ID="Type"
015.                                        runat="server"
016.                                        Enabled="false"
017.                                        EmptyMessage="Type"
018.                                        AutoPostBack="false"
019.                                        Text='<%# Eval("Type") %>'>
020.                                    </telerik:RadTextBox>
021.                                </div>
022.                                <div class="inputwrap">
023.                                    <label for="Principal">Principal: </label>
024.                                    <telerik:RadTextBox ID="Principal"
025.                                        runat="server"
026.                                        Enabled="false"
027.                                        AutoPostBack="false"
028.                                        Text='<%# Eval("Principal") %>'>
029.                                    </telerik:RadTextBox>
030.                                </div>
031.                            </div>
032.                            <div class="inputwrap">
033.                                <label for="NumeroUtilisateur">Numéro d'utilisateur:  </label>
034.                                <telerik:RadTextBox ID="NumeroUtilisateur"
035.                                    runat="server"
036.                                    Enabled="false"
037.                                    EmptyMessage="Type"
038.                                    AutoPostBack="false"
039.                                    Text='<%# Eval("NumeroUtilisateur") %>'>
040.                                </telerik:RadTextBox>
041.                            </div>
042.                            <div class="inputwrap">
043.                                <label for="NomPrenom">Nom: </label>
044.                                <telerik:RadTextBox ID="NomPrenom"
045.                                    runat="server"
046.                                    Enabled="false"
047.                                    EmptyMessage="NomPrenom"
048.                                    AutoPostBack="false"
049.                                    Text='<%# Eval("NomPrenom") %>'>
050.                                </telerik:RadTextBox>
051.                            </div>
052.                            <div class="inputwrap">
053.                                <label for="Courriel">Courriel: </label>
054.                                <telerik:RadTextBox ID="Courriel"
055.                                    runat="server"
056.                                    Enabled="false"
057.                                    EmptyMessage="Courriel"
058.                                    AutoPostBack="false"
059.                                    Text='<%# Eval("Courriel") %>'>
060.                                </telerik:RadTextBox>
061.                            </div>
062.                            <div class="inputwrap">
063.                                <label for="CompteCentral">Compte Central: </label>
064.                                <telerik:RadTextBox ID="CompteCentral"
065.                                    runat="server"
066.                                    Enabled="false"
067.                                    EmptyMessage="Compte Central"
068.                                    AutoPostBack="false"
069.                                    Text="ND">
070.                                </telerik:RadTextBox>
071.                            </div>
072.                            <div class="inputwrap">
073.                                <label for="DateModification">Date Modification: </label>
074.                                <telerik:RadTextBox ID="DateModification"
075.                                    runat="server"
076.                                    Enabled="false"
077.                                    EmptyMessage="DateModification"
078.                                    AutoPostBack="false"
079.                                    Text='<%# Eval("DateModification") %>'>
080.                                </telerik:RadTextBox>
081.                            </div>
082.                            <div class="inputwrap">
083.                                <label for="DateUtilisation">Dernière utilisation: </label>
084.                                <telerik:RadTextBox ID="DateUtilisation"
085.                                    runat="server"
086.                                    Enabled="false"
087.                                    EmptyMessage="DateUtilisation"
088.                                    AutoPostBack="false"
089.                                    Text='<%# Eval("DateUtilisation") %>'>
090.                                </telerik:RadTextBox>
091.                            </div>
092.                            <h2 class="DetailTitle">Compte</h2>
093.                            <br>
094.                            <div class="inputwrap">
095.                                <label for="Compte">Compte: </label>
096.                                <telerik:RadTextBox ID="Compte"
097.                                    runat="server"
098.                                    Enabled="false"
099.                                    EmptyMessage="Compte"
100.                                    AutoPostBack="false"
101.                                    Text='<%# Eval("Compte") %>'>
102.                                </telerik:RadTextBox>
103.                            </div>
104.                            <div class="inputwrap">
105.                                <label for="TypeCompte">Type de compte: </label>
106.                                <telerik:RadTextBox ID="TypeCompte"
107.                                    runat="server"
108.                                    Enabled="false"
109.                                    EmptyMessage="TypeCompte"
110.                                    AutoPostBack="false"
111.                                    Text='<%# Eval("TypeCompte") %>'>                    
112.                                </telerik:RadTextBox>
113.                            </div>
114.                            <div class="inputwrap">
115.                                <label for="Statut">Statut: </label>
116.                                <telerik:RadTextBox ID="Statut"
117.                                    runat="server"
118.                                    Enabled="false"
119.                                    EmptyMessage="Statut"
120.                                    AutoPostBack="false"
121.                                    Text='<%# Eval("Statut") %>'>
122.                                </telerik:RadTextBox>
123.                            </div>
124.                            <div class="inputwrap">
125.                                <label for="DateStatut">Depuis: </label>
126.                                <telerik:RadTextBox ID="DateStatut"
127.                                    runat="server"
128.                                    Enabled="false"
129.                                    EmptyMessage="DateStatut"
130.                                    AutoPostBack="false"
131.                                    Text='<%# Eval("DateStatut") %>'>
132.                                </telerik:RadTextBox>
133.                            </div>
134.                            <telerik:RadButton RenderMode="Lightweight"
135.                                runat="server"
136.                                ID="BoutonModifier"
137.                                Visible="true"
138.                                Text="Modifier"
139.                                CommandName="Edit"
140.                                CssClass="detailButton" >
141.                            <Icon SecondaryIconCssClass="rbEdit"></Icon>
142.                                </telerik:RadButton>
143.                        </fieldset>
144.                    </ItemTemplate>
145.                    <EditItemTemplate>
146.                        <fieldset class="form">
147.                            <div id="teteDroit" runat="server">
148.                                <h2 class="DetailTitle">Utilisateur</h2>
149.                                <div class="inputwrap">
150.                                    <label for="Type">Type: </label>
151.                                    <telerik:RadTextBox ID="Type"
152.                                        runat="server"
153.                                        AutoPostBack="false"
154.                                        Text='<%# Bind("Type") %>'/>
155.                                </div>
156.                                <div class="inputwrap">
157.                                    <label for="Principal">Principal: </label>
158.                                    <telerik:RadTextBox ID="Principal"
159.                                        runat="server"
160.                                        AutoPostBack="false"
161.                                        Text='<%# Bind("Principal") %>'>
162.                                    </telerik:RadTextBox>
163.                                </div>
164.                            </div>
165.                            <div class="inputwrap">
166.                                <label for="NumeroUtilisateur">Numéro d'utilisateur:  </label>
167.                                <telerik:RadTextBox ID="NumeroUtilisateur"
168.                                    runat="server"
169.                                    AutoPostBack="false"
170.                                    Text='<%# Bind("NumeroUtilisateur") %>'>
171.                                </telerik:RadTextBox>
172.                            </div>
173.                            <div class="inputwrap">
174.                                <label for="NomPrenom">Nom: </label>
175.                                <telerik:RadTextBox ID="NomPrenom"
176.                                    runat="server"
177.                                    AutoPostBack="false"
178.                                    Text='<%# Bind("NomPrenom") %>'>
179.                                </telerik:RadTextBox>
180.                            </div>
181.                            <div class="inputwrap">
182.                                <label for="Courriel">Courriel: </label>
183.                                <telerik:RadTextBox ID="Courriel"
184.                                    runat="server"
185.                                    AutoPostBack="false"
186.                                    Text='<%# Bind("Courriel") %>'>
187.                                </telerik:RadTextBox>
188.                            </div>
189.                            <div class="inputwrap">
190.                                <label for="CompteCentral">Compte Central: </label>
191.                                <telerik:RadTextBox ID="CompteCentral"
192.                                    runat="server"
193.                                    AutoPostBack="false"
194.                                    Text="ND">
195.                                </telerik:RadTextBox>
196.                            </div>
197.                            <div class="inputwrap">
198.                                <label for="DateModification">Date Modification: </label>
199.                                <telerik:RadTextBox ID="DateModification"
200.                                    runat="server"
201.                                    AutoPostBack="false"
202.                                    Text='<%# Bind("DateModification") %>'>
203.                                </telerik:RadTextBox>
204.                            </div>
205.                            <div class="inputwrap">
206.                                <label for="DateUtilisation">Dernière utilisation: </label>
207.                                <telerik:RadTextBox ID="DateUtilisation"
208.                                    runat="server"
209.                                    AutoPostBack="false"
210.                                    Text='<%# Bind("DateUtilisation") %>'>
211.                                </telerik:RadTextBox>
212.                            </div>
213.                            <h2 class="DetailTitle">Compte</h2>
214.                            <br>
215.                            <div class="inputwrap">
216.                                <label for="Compte">Compte: </label>
217.                                <telerik:RadTextBox ID="Compte"
218.                                    runat="server"
219.                                    AutoPostBack="false"                                 
220.                                    Text='<%# Bind("Compte") %>'>
221.                                </telerik:RadTextBox>
222.                            </div>
223.                            <div class="inputwrap">
224.                                <label for="TypeCompte">Type de compte: </label>
225.                                <telerik:RadTextBox ID="TypeCompte"
226.                                    runat="server"
227.                                    AutoPostBack="false"
228.                                    Text='<%# Bind("TypeCompte") %>'>
229.                                </telerik:RadTextBox>
230.                            </div>
231.                            <div class="inputwrap">
232.                                <label for="Statut">Statut: </label>
233.                                <telerik:RadTextBox ID="Statut"
234.                                    runat="server"
235.                                    AutoPostBack="false"
236.                                    Text='<%# Bind("Statut") %>'>
237.                                </telerik:RadTextBox>
238.                            </div>
239.                            <div class="inputwrap">
240.                                <label for="DateStatut">Depuis: </label>
241.                                <telerik:RadTextBox ID="DateStatut"
242.                                    runat="server"
243.                                    AutoPostBack="false"
244.                                    Text='<%# Bind("DateStatut") %>'>
245.                                </telerik:RadTextBox>
246.                            </div>
247.                            </div>
248.                            <telerik:RadButton RenderMode="Lightweight"
249.                                ID="updateBouton"
250.                                Text="Enregistrer"
251.                                runat="server"
252.                                OnClick="updateBouton_Click">
253.                            <Icon SecondaryIconCssClass="rbSave"></Icon>
254.                                </telerik:RadButton>
255.                            <telerik:RadButton RenderMode="Lightweight"
256.                                ID="BoutonInsert"
257.                                Text="Insert"
258.                                runat="server"
259.                                CommandName="Insert"
260.                                AutoPostBack="true" >
261.                                <Icon SecondaryIconCssClass="rbAdd"></Icon>
262.                                </telerik:RadButton>
263.                            <telerik:RadButton RenderMode="Lightweight"
264.                                ID="BoutonAnnuler"
265.                                Text="Annuler"
266.                                runat="server"
267.                                CausesValidation="false"
268.                                CommandName="Cancel" >
269.                                <Icon SecondaryIconCssClass="rbCancel"></Icon>
270.                                </telerik:RadButton>
271.                        </fieldset>
272.                    </EditItemTemplate>
273.                </telerik:RadDataForm>

 

 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 07 Dec 2016, 11:32 AM
Hi Rolland,

You need to implement the logic for updating the items in the UpdateMethod specified in the ObjectDataSource:

Best Regards,
Konstantin Dikov
Telerik by Progress
Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
Tags
DataForm
Asked by
Rolland
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or