Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DropDownList Works in InsertItemTemplate but not in EditItemTempla

Reply
Thread Tools

DropDownList Works in InsertItemTemplate but not in EditItemTempla

 
 
David
Guest
Posts: n/a
 
      12-22-2009
I have a formview item that displays a record. That record comes from the
Quotes table. One of the fields is the Requestor field. When creating a new
record, I display a dropdownlist that contains employee records from the
Employee table. The employee table has an EmployeeID field and a Name field.

So, in the InsertItemTemplate of the formview object, I have this:



<aspropDownList runat="server" ID="ddlRequestor"
DataSourceID="SQLDataSourceRequestors" DataTextField="Name"
DataValueField="EmployeeID" SelectedValue='<%# Bind("EmployeeID")
%>'></aspropDownList>


Excellent. Works perfect. On the Inserting event, I grap the ID selected
in the dropdownlist, and put it into the Insert statement for the formview.

Now, I go to edit the record. I use the exact same code in my
EditItemTemplate. (I just copied and pasted the code, so I know it’s the
same thing.)

As soon as I hit the “Edit” button, I get an exception

DataBinding: 'System.Data.DataRowView' does not contain a property with the
name 'EmployeeID'.


So, what’s different when running the EditItemTemplate, compared with the
InsertItemTemplate?

 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      12-22-2009
=?Utf-8?B?RGF2aWQ=?= <> wrote in
news:27485640-FBCB-44CB-AF75-:

> So, what Ts different when running the EditItemTemplate, compared
> with the InsertItemTemplate?


You are custom binding with the insert template, but not binding
propertly when the user clicks edit. That is where your blow up is
happening. Step through the code, if you want this solution.

NOTE: I prefer using a form view instead of edit template in the grid
view. There are exceptions, of course, where it makes sense the user
quickly update dozens of rows. In general, however, an edit is more than
just changing one field. In those cases, isolating the change reduces
the user's chance of error, as they are focusing on a single record.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
 
 
 
Thomas Sun [MSFT]
Guest
Posts: n/a
 
      12-23-2009
Hi David,

Using InsertItemTemplate to insert data, there is no data to be bound to
the FormView when Insert button is clicked in FormView.

Using EditItemTemplate to update data, the data will be rebound to the
EditItemTemplate When the Edit button is clicked. In this case, ASP.NET
will check whether the Field "employeeID" exists.

So please make sure this field is included in the select statement of
FormView.

For more information about using the FormView to do flexible data
modification, see
http://www.asp.net/learn/data-access...ial-16-cs.aspx (Section: Using
the FormView for a More Flexible Data Modification User Interface).

I look forward to receiving your test results.


--------------------
|
| I have a formview item that displays a record. That record comes from
the
| Quotes table. One of the fields is the Requestor field. When creating a
new
| record, I display a dropdownlist that contains employee records from the
| Employee table. The employee table has an EmployeeID field and a Name
field.
|
| So, in the InsertItemTemplate of the formview object, I have this:
|
|
|
| <aspropDownList runat="server" ID="ddlRequestor"
| DataSourceID="SQLDataSourceRequestors" DataTextField="Name"
| DataValueField="EmployeeID" SelectedValue='<%# Bind("EmployeeID")
| %>'></aspropDownList>
|
|
| Excellent. Works perfect. On the Inserting event, I grap the ID
selected
| in the dropdownlist, and put it into the Insert statement for the
formview.
|
| Now, I go to edit the record. I use the exact same code in my
| EditItemTemplate. (I just copied and pasted the code, so I know it’s
the
| same thing.)
|
| As soon as I hit the “Edit?button, I get an exception
|
| DataBinding: 'System.Data.DataRowView' does not contain a property with
the
| name 'EmployeeID'.
|
|
| So, what’s different when running the EditItemTemplate, compared with
the
| InsertItemTemplate?
|
|





Best Regards,
Thomas Sun

Microsoft Online Partner Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

With newsgroups, MSDN subscribers enjoy unlimited, free support as opposed
to the limited number of phone-based technical support incidents. Complex
issues or server-down situations are not recommended for the newsgroups.
Issues of this nature are best handled working with a Microsoft Support
Engineer using one of your phone-based incidents.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDownLIst populated by xml file works in IE but not Firefox William LaMartin ASP .Net 2 08-16-2008 03:01 AM
Formview insertitemtemplate won't populate dropdownlist in Insert Mode jobs at webdos ASP .Net 0 10-09-2006 03:35 PM
When I turn on my PC, it works, works, works. Problem! Fogar Computer Information 1 01-17-2006 12:57 AM
[py2exe.i18n] English works, German works, but not French. What do I miss? F. GEIGER Python 3 08-06-2004 10:01 AM
After rebooting my PC works, works, works! Antivirus problem? Adriano Computer Information 1 12-15-2003 05:30 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57