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 -