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

ExtractValuesFromItem from GridNumericColumn with DataFormatString

5 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
alo
Top achievements
Rank 1
alo asked on 25 Jul 2008, 08:02 PM
I am using the following technique to extract data from a GridNumericColumn:

        e.Item.OwnerTableView.ExtractValuesFromItem(NewValues, EditedItem);  
 
        foreach (DictionaryEntry Entry in NewValues)  
        {  
            if (Entry.Value == null)  
            {  
                NewRow[(string)Entry.Key] = DBNull.Value;  
            }  
            else 
            {  
                NewRow[(string)Entry.Key] = Entry.Value;  
            }  
        } 

This works fine until I add a DataFormatString to format the number to a currency.  When the format is applied, the Entry.Value returns a string with the formatting (e.g., "$1,000.00"), which of course won't load into its corresponding numeric field in the new row.

Is there a way using this approach to extract the value without the formatting?

I also have a similar problem when using the GridDateTimeColumn with a DataFormatString.

Thanks,

Al

5 Answers, 1 is accepted

Sort by
0
Missing User
answered on 29 Jul 2008, 07:59 AM
Hello Al O,

We tried to reproduce the problem you reported, but without much success. Please refer to the attached project as part of our local tests. It worked as expected at our side. What is different in your case?

Regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
alo
Top achievements
Rank 1
answered on 04 Aug 2008, 03:43 AM

In my case, I'm extracting the values for all the rows in the grid in a method that references the grid.  Your example is extracting the data from one row using the event argument.

I've modified your example to show my scenario.  Add a button to your example and then add the following code to the button's click event:

    protected void Button1_Click(object sender, EventArgs e)  
    {  
        foreach (GridDataItem dataItem in RadGrid1.Items)  
        {  
            Hashtable newValues = new Hashtable();  
            dataItem.OwnerTableView.ExtractValuesFromItem(newValues, dataItem);  
 
            foreach (DictionaryEntry Entry in newValues)  
            {  
                Response.Write(Entry.Value.ToString());  
            }  
 
        }  
    } 

Run the example and click on the button.  You should see the "$" is being returned for each value (i.e., $1$2$3).

Thanks,

Al

0
plamen
Top achievements
Rank 1
answered on 06 Aug 2008, 02:07 PM
hi

You can replace the "$" character with String.Empty, here is an example:


Response.Write(Entry.Value.ToString().Replace("$", String.Empty));


Regards...
<John:Peel />
0
alo
Top achievements
Rank 1
answered on 06 Aug 2008, 04:24 PM
Thanks for the tip.  I consider that a good work around, but I still would expect the ExtractValuesFromItem method to work in my scenario the same way as in their example which automatically removes the formatting characters.

Thanks again,

Al
0
Accepted
Yavor
Telerik team
answered on 07 Aug 2008, 05:57 AM
Hi,

This method is actually used to extract values from item(s) which are being edited, and are in edit mode. Hence, you can use the method supplied earlier, or alternatively access the items as shown here.
I hope these are suitable options for you.

Greetings,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
alo
Top achievements
Rank 1
Answers by
Missing User
alo
Top achievements
Rank 1
plamen
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or