DropDownList Works in InsertItemTemplate but not in EditItemTempla

D

David

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:



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


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?
 
G

Gregory A. Beamer

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! |
*******************************************
 
T

Thomas Sun [MSFT]

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/tutorial-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:
|
|
|
| <asp:DropDownList runat="server" ID="ddlRequestor"
| DataSourceID="SQLDataSourceRequestors" DataTextField="Name"
| DataValueField="EmployeeID" SelectedValue='<%# Bind("EmployeeID")
| %>'></asp:DropDownList>
|
|
| 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/subscriptions/managednewsgroups/default.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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top