ExtractValuesFromItem from GridNumericColumn with DataFormatString

6 posts, 1 answers
  1. alo
    alo avatar
    53 posts
    Member since:
    Jan 2009

    Posted 25 Jul 2008 Link to this post

    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
  2. Plamen Peshev
    Admin
    Plamen Peshev avatar
    886 posts

    Posted 29 Jul 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. alo
    alo avatar
    53 posts
    Member since:
    Jan 2009

    Posted 03 Aug 2008 Link to this post

    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

  5. John
    John avatar
    416 posts
    Member since:
    Oct 2006

    Posted 06 Aug 2008 Link to this post

    hi

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


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


    Regards...
    <John:Peel />
  6. alo
    alo avatar
    53 posts
    Member since:
    Jan 2009

    Posted 06 Aug 2008 Link to this post

    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
  7. Answer
    Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 07 Aug 2008 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017