Solved

Trouble with DetailsView, OnItemUpdating

Posted on 2007-12-05
7
2,155 Views
Last Modified: 2012-05-05
Created a Dynamic DetailsView (basically adding bound fields to DetailsView fields) and I'm having trouble using OnItemUpdating command.

I can populate the form but I'm unable to capture any values on the update.
asp:
 
<asp:DetailsView ID="DetailViewEdit" 
   runat="server"
   AutoGenerateRows="false" 
   OnItemUpdating="DetailViewEdit_ItemUpdating"
   AutoGenerateEditButton="true"
   DefaultMode="Edit" 
   />
 
.cs code:
 
..
  BoundField bf = new BoundField();
  bf.DataField = field.Key;
  bf.HeaderText = field.Name;
  
  DetailViewEdit.Fields.Add(bf);
 
DetailViewEdit.DataKeyNames = field.Key
DetailViewEdit.DataSource = referenceDataTable;
DetailViewEdit.DataBind();
 
...
protected void DetailViewEdit_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
 
e.NewValues  <-- empty
e.OldValues  <-- empty
e.Keys <-- empty

Open in new window

0
Comment
Question by:ebuechel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20415848
what do you want to do in the item updating event? kinda what you are trying to implement using that event?
0
 

Author Comment

by:ebuechel
ID: 20416428
Pulled changed key/value pairs for use in a custom store procedure call.

I could hack the request form - DetailViewEdit.ClientID.Replace('$', '_')  - but that seems a little too sloppy.


        foreach (DictionaryEntry entry in e.NewValues)
        {
              // New Edits, entry.Key : entry.Value

        }
0
 
LVL 10

Expert Comment

by:digitalZo
ID: 20418710
You have to use the DataKey to capture the values.

http://www.mcse.ms/message2536642.html
protected void DetailsView1_ItemUpdating(object sender,
 
DetailsViewUpdateEventArgs e)
 
{
 
int id = (int)DetailsView1.DataKey[0];
 
TextBox txtName = DetailsView1.FindControl("txtName") as TextBox;
 
string newname = txtName.Text;

Open in new window

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:ebuechel
ID: 20419905
Not sure if that example exactly relates as I'm creating the Bound Fields on the fly:

...
  BoundField bf = new BoundField();
  bf.DataField = field.Key;
  bf.HeaderText = field.Name;
 
  DetailViewEdit.Fields.Add(bf);

DetailViewEdit.DataSource = referenceDataTable;
DetailViewEdit.DataBind();


DetailViewEdit.FindControl(field.Key) as TextBox;  <-- is null
0
 

Author Comment

by:ebuechel
ID: 20425078
http://forums.asp.net/p/1034786/1427427.aspx

Found the solution.


thx.
        for (int i = 0; i < DetailViewEdit.Fields.Count; i++)
        {
            DataControlFieldCell cellNormal = detailsView.Rows[i].Cells[0] as DataControlFieldCell;
            detailsView.Fields[i].ExtractValuesFromCell(e.Keys, cellNormal, DataControlRowState.Normal, true);
 
            DataControlFieldCell cellEdit = detailsView.Rows[i].Cells[1] as DataControlFieldCell;
            detailsView.Fields[i].ExtractValuesFromCell(e.NewValues, cellEdit, DataControlRowState.Edit, false);
        }
 
 
        foreach (string key in e.Keys.Keys)
        {
            Utilities.Log.WriteFileEntry("Key(" + key + ") - Value:" + e.Keys[key], Log.Priority.Medium);
        }
 
        foreach (string key in e.NewValues.Keys)
        {
            Utilities.Log.WriteFileEntry("NewValues Key(" + key + ") - Value:" + e.NewValues[key], Log.Priority.Medium);
        }

Open in new window

0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 20592634
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IEnumerable<T> to a List<T> 8 54
How to identify a paragraph in the body of text? 2 55
Selenium and Xpath 4 35
C# DataTable (in memory) vs SQL Lookups 4 37
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question