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

Suggestion for ExtractValues

8 Answers 302 Views
Grid
This is a migrated thread and some comments may be shown as answers.
skysailor
Top achievements
Rank 1
skysailor asked on 08 May 2008, 06:23 AM
Hi,
I would like to suggest that you extend the RadGrid GridEditFormItem.ExtractValues method to support updating any business object. It could use reflection to find any properties that match the names of data bound columns.

This would make the data binding very powerful! If you don't use declarative databinding getting the values back into your database is a pain. But being able to simply update a LINQ generate entity object with a single method call would be a huge improvement.

So instead of doing :-
    Hashtable values = new Hashtable();  
    item.ExtractValues(values);  
 
    C.CategoryValue = (string)values["CategoryValue"];  
    C.Selectable_ = (bool)values["Selectable_"];  
// etc. for all fields  
 

You could do :-
    item.ExtractValues(C); 

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 12 May 2008, 09:10 AM
Hi skysailor,

We can add UpdateValues() method where you can provide desired object instance and the grid will call internally ExtractValues() and will set respective values using reflection.

Let me know what you think.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
skysailor
Top achievements
Rank 1
answered on 12 May 2008, 11:52 PM
Hi Vlad,
That would be fantastic!
I don't like the automatic updates using declarative datasources. It doesn't give you enough control. I prefer to use my own business objects that I load and save. Adding an UpdateValues method would make databinding much simpler and give you control over the process.
Thanks,
Clayton.
0
Accepted
Vlad
Telerik team
answered on 13 May 2008, 06:51 AM
Hi Clayton,

We added the method and this will be available officially with our first service pack later this week. I have added 2000 Telerik points to your account.

Keep posting great ideas!

Kind regards,

Vlad
the Telerik team


Instantly find answers to your questions at the new Telerik Support Center
0
skysailor
Top achievements
Rank 1
answered on 19 May 2008, 12:59 AM
Hi,
I have in stalled the new SP1 and the feature is great! Thankyou very much.
I did however find one small issue. If a column is a string type and no text is entered then the returned value from ExtractValues is NULL. Your code seems to be trying to call a method on the null which gives an exception.
Clatyon.
0
Vlad
Telerik team
answered on 22 May 2008, 02:13 PM
Thanks Clatyon!

We fixed this immediately - I have added 1000 Telerik points to your account.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
idwaikat
Top achievements
Rank 2
answered on 18 Mar 2009, 03:31 PM
I want to ask a question please

I am using the following snippet of code:

Private Sub MyFunction(ByVal row As Telerik.Web.UI.GridDataItem)

   Dim data As New Dictionary(Of String, Object)
   row.ExtractValues(data)
   Dim mytype As String=row("id").GetType().ToString()

End Sub


although [id] stored in database as integer and returned in the datatable as integer also,but  mytype always string,

you may tell me that it's because of the value type of Dictionary is Object, but if I do it like this:

data.Add("myid",1)
mytype  = data("myid").GetType.ToString()

the type of myid is [System.int32]


the question is that why it's always string??? I need to make some mathematics for the values...



0
idwaikat
Top achievements
Rank 2
answered on 24 Mar 2009, 10:05 AM
I wrote the following code which corrects the issue i talked about previously , this function works exactly like row.ExtractValues, but it returns the correct format for each cell, not always (string)..


public static void ExtractValues(ref Telerik.Web.UI.GridDataItem row, ref Dictionary<string, object> data)
        {
            RadGrid rgrid = (RadGrid)row.Parent.Parent.Parent;

            for (int index = 0; index < rgrid.MasterTableView.Columns.Count; index++)
            {
                Type type = Type.GetType(rgrid.MasterTableView.Columns[index].DataType.ToString());
                object obj = Convert.ChangeType(row[rgrid.MasterTableView.Columns[index].UniqueName].Text, type);
                data.Add(rgrid.MasterTableView.Columns[index].UniqueName, obj);
            }

            for (int index = 0; index < rgrid.MasterTableView.AutoGeneratedColumns.Length; index++)
            {
                Type type = Type.GetType(rgrid.MasterTableView.AutoGeneratedColumns[index].DataType.ToString());
                object obj = Convert.ChangeType(row[rgrid.MasterTableView.AutoGeneratedColumns[index].UniqueName].Text, type);
                data.Add(rgrid.MasterTableView.AutoGeneratedColumns[index].UniqueName, obj);
            }
        }




0
Rosen
Telerik team
answered on 24 Mar 2009, 10:41 AM
Hi Ibrahim,

I'm glad that you have manage to solve the issue you were facing.
As to the RadGrid's ExtractValues method behavior. The method acts this way in order to be consistent with MS's GridView's ExtractRowValues behavior.

Best wishes,
Rosen
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
skysailor
Top achievements
Rank 1
Answers by
Vlad
Telerik team
skysailor
Top achievements
Rank 1
idwaikat
Top achievements
Rank 2
Rosen
Telerik team
Share this question
or