CodeSmith Community
Your Code. Your Way. Faster!

How can I get FormView_ItemUpdating notification with ManyToManyListRelationship

Latest post 01-26-2007 12:51 PM by dwrcalgary. 2 replies.
  • 01-25-2007 1:29 PM

    • dwrcalgary
    • Top 500 Contributor
    • Joined on 08-21-2006
    • Calgary, Alberta, Canada
    • Posts 9
    • Points 195

    How can I get FormView_ItemUpdating notification with ManyToManyListRelationship

    I have a simple:

    <asp:FormView runat="server" DataKeyNames="PrimaryID" DataSourceID="PrimaryDataSource" DefaultMode="Edit" OnItemUpdated="FormView1_ItemUpdated">
    <EditItemTemplate>
    ...
    <asp:ListBox ID="ListBox1" runat="server" DataSourceID="ReferenceDataSource" DataTextField="ShortName" DataValueField="ReferenceID" SelectionMode="Multiple"></asp:ListBox>
    ...
    <data:ManyToManyListRelationship ID="ManyToManyRelationship1" runat="server">
    <PrimaryMember runat="server" DataSourceID="PrimaryDataSource" EntityKeyName="PrimaryID" />
    <LinkMember runat="server" DataSourceID="LinkDataSource" EntityKeyName="PrimaryID" ForeignKeyName="ReferenceID" />
    <ReferenceMember runat="server" DataSourceID="ReferenceDataSource" ListControlID="ListBox1" EntityKeyName="ReferenceID" />
    </data:ManyToManyListRelationship>
    </EditItemTemplate>
    </asp:FormView>

    Which works [amazingly] by the way...

    However I'm not sure how to find out if there were any changes made to the many to many relationship
    For example something like this:

    protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
      // Would like to do some code here if the user made any changes to the ManyToMany relationships
      // if (e.NewValues["ManyToManyRelationship1"] != e.OldValues["ManyToManyRelationship1"])

    }

    Anyone have any ideas?

    Also, adding a

    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)

    doesn't really work as it fires after the FormView1_ItemUpdating... ItemUpdated events. 

    • Post Points: 35
  • 01-26-2007 10:29 AM In reply to

    Re: How can I get FormView_ItemUpdating notification with ManyToManyListRelationship

    Hi,
    Because the values are never changing for the ListBox.  That's why it's not updated. 

    I would except that the SelectedIndexChanged would give you the events you're looking for.  You need to add AutoPostBack="true" to the ListBox, so that it would fire this event.


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 01-26-2007 12:51 PM In reply to

    • dwrcalgary
    • Top 500 Contributor
    • Joined on 08-21-2006
    • Calgary, Alberta, Canada
    • Posts 9
    • Points 195

    Re: How can I get FormView_ItemUpdating notification with ManyToManyListRelationship

    Very true I did forget the AutoPostback="true" however that fires whenever a user changes the selection on the list

    What I really want is to do some work when the user updates the formview... my current hack is this:

    protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
      if (ViewState["ChangedManyToManyLists"] != null && (bool)ViewState["ChangedManyToManyLists"])
      {
        // do some work
      }
    }

    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
      ViewState[
    "ChangedManyToManyLists"] = true;
    }

    • Post Points: 5
Page 1 of 1 (3 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems