DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 15 Aug 2007 10:59:14 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Yin99
          2    Ladislav Mrnka
          3    Yin99


FormView change data before hitting database?   
I have the code below and get the error "cannot change read only
object insied a foreach loop"  I am hoping someone could graciously
provide code example of how I could do this?  Thanks!  - Yin

       foreach (DictionaryEntry entry in e.Values)
          {

           if (String.Compare(entry.Key.ToString(),"CustomerID")==0) {
              entry.Value = "5";
          }
          }
Date:Wed, 15 Aug 2007 10:59:14 -0700   Author:  

RE: FormView change data before hitting database?   
Hi Yin,
DictionaryEntry is a structure = value type. You cannot modify any of its 
properties when it is returned by Enumerator (the way how the foreach command 
is handled internally).

Where do you call this block of code? What type is the e? What type of data 
source are you using? Data source controls generally provides set of events 
like Inserting, Updating etc. which allows you to update values before you 
send them to data source.

Regards,
Ladislav 

"Yin99" wrote:


> 
> I have the code below and get the error "cannot change read only
> object insied a foreach loop"  I am hoping someone could graciously
> provide code example of how I could do this?  Thanks!  - Yin
> 
>        foreach (DictionaryEntry entry in e.Values)
>           {
> 
>            if (String.Compare(entry.Key.ToString(),"CustomerID")==0) {
>               entry.Value = "5";
>           }
>           }
> 
> 
Date:Wed, 15 Aug 2007 12:22:02 -0700   Author:  

Re: FormView change data before hitting database?   
Thanks for the reply.  Actually I found solution to my problem... I
was trying to set value of a field in the formview
(CustomerID) before it writes the record to the database.  I had to
problems,  1)  not putting the correct ID for the control in
FindControl call so I was getting null  2)  not calling in right
place.    So I now have this code and it works-
(I used ItemCommand because this event seems to happen before anything
touches the database, but maybe there is a better event to put it in?)


 protected void FormView1_ItemCommand(object sender,
FormViewCommandEventArgs e)
    {
        TextBox txtbox = ((TextBox)
(FormView1.FindControl("CustomerID")));
        if (txtbox != null) {
            txtbox.Text = "5";
        }
    }



On Aug 15, 2:22 pm, Ladislav Mrnka
 wrote:

> Hi Yin,
> DictionaryEntry is a structure = value type. You cannot modify any of its
> properties when it is returned by Enumerator (the way how the foreach command
> is handled internally).
>
> Where do you call this block of code? What type is the e? What type of data
> source are you using? Data source controls generally provides set of events
> like Inserting, Updating etc. which allows you to update values before you
> send them to data source.
>
> Regards,
> Ladislav
>
>
>
> "Yin99" wrote:
>
> > I have the code below and get the error "cannot change read only
> > object insied a foreach loop"  I am hoping someone could graciously
> > provide code example of how I could do this?  Thanks!  - Yin
>
> >        foreach (DictionaryEntry entry in e.Values)
> >           {
>
> >            if (String.Compare(entry.Key.ToString(),"CustomerID")==0) {
> >               entry.Value = "5";
> >           }
> >           }- Hide quoted text -
>
> - Show quoted text -
Date:Wed, 15 Aug 2007 13:56:51 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us