473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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";
}
}

Aug 15 '07 #1
2 2150
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";
}
}

Aug 15 '07 #2
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
<LadislavMr...@discussions.microsoft.comwrote:
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 -

Aug 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ottar | last post by:
I have a few numeric fields, and when I update i get the error: "Input string was not in a correct format". Next line:" System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&...
1
by: Shawn Wildermuth | last post by:
I have a *single* SqlDataSource that loads up a single result set that I show in a GridView. In the GridView, i've added a "Select" button and handling the SelectedItem event. I also have a...
3
by: sck10 | last post by:
Hello, I am creating a form for users to enter information about a lab and the members of the lab. I have one form (FormView) that they use to enter information about that lab. The keyvalue is...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
3
by: Jurgen Appelo | last post by:
I asked this question earlier, but unfortunately the two replies I got did not solve the problem. Here it is again, but now with the code: After an Update my FormView always loses its viewstate...
2
by: Kelly | last post by:
I'm fairly new to ASP.NET2, but I have an ASP 3.0 background, and I've been experimenting with the DataSource and FormView widgets. I wound up having some questions along the way which I hope you...
0
by: sanjeev06 | last post by:
When Updating using a FormView and ObjectDataSource, the formview always does the data-binding of its controls and the field values in the FormView are always overwritten by the results of the...
1
by: TheDude5B | last post by:
Hi, I have created the Insert Template for my FormView on an aspx page using asp.net 2.0. Inside this FormView I have some TextBox's and other elements. One of these elements is a DropDownList...
3
by: KaOne | last post by:
Hi All, excuse me in advance for my not very perfect english. I need some help about a problem with a FormView bounded to an ObjectDataSource. In practise I have an ObjectDataSource that uses some...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.