DropDownList Works in InsertItemTemplate but not in EditItemTempla

Discussion in 'ASP .Net' started by David, Dec 22, 2009.

  1. David

    David Guest

    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?
     
    David, Dec 22, 2009
    #1
    1. Advertising

  2. =?Utf-8?B?RGF2aWQ=?= <> wrote in
    news::

    > 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! |
    *******************************************
     
    Gregory A. Beamer, Dec 22, 2009
    #2
    1. Advertising

  3. 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.
     
    Thomas Sun [MSFT], Dec 23, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pjbates
    Replies:
    1
    Views:
    4,543
    Dan Vogt
    May 2, 2006
  2. F. GEIGER
    Replies:
    3
    Views:
    784
    F. GEIGER
    Aug 6, 2004
  3. jobs at webdos
    Replies:
    0
    Views:
    704
    jobs at webdos
    Oct 9, 2006
  4. David Wang
    Replies:
    0
    Views:
    737
    David Wang
    Dec 1, 2006
  5. William LaMartin
    Replies:
    2
    Views:
    824
    William LaMartin
    Aug 16, 2008
Loading...

Share This Page