Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding parameters to the UpdateMethod of an ObjectDataSource
    primarykey
    data
    text
    <p>Ok, so I am working with ASP WebForms and have a ListView (for account customers) inside another ListView (for accounts).</p> <p>This inner ListView has an ObjectDataSource for the account customers (referred to as participants in this particular application).</p> <p>Here it is:</p> <pre><code>&lt;asp:ObjectDataSource ID="dataSourceParticipants" runat="server" SelectMethod="GetParticipantsForAccount" UpdateMethod="UpdateParticipantDetails" DeleteMethod="DeleteParticipantDetails" InsertMethod="InsertParticipantDetails" TypeName="PreScreening2.AccountManagerWrapper" DataObjectTypeName="PreScreening2.BLL.Models.Participant"&gt; &lt;SelectParameters&gt; &lt;asp:ControlParameter ControlID="grdAccounts" Name="accountNumber" PropertyName="SelectedDataKey.Values[AccountNumber]" Type="String" /&gt; &lt;/SelectParameters&gt; &lt;/asp:ObjectDataSource&gt; </code></pre> <p>And here is my AccountManagerWrapper class (poorly named):</p> <pre><code>public class AccountManagerWrapper { [Inject] public IAccountManager AccountManager { get; set; } [Inject] public IParticipantManager ParticipantManager { get; set; } public IEnumerable&lt;Participant&gt; GetParticipantsForAccount(string accountNumber) { return AccountManager.GetParticipantsForAccount(accountNumber); } public bool UpdateParticipantDetails(Participant participant) { return ParticipantManager.UpdateParticipantDetails(participant, null, AccountManager); } public bool DeleteParticipantDetails(Participant participant) { return ParticipantManager.DeleteParticipant(participant, null, AccountManager); } public bool InsertParticipantDetails(Participant participant) { return ParticipantManager.UpdateParticipantDetails(participant, null, AccountManager); } } </code></pre> <p>On the <strong>ItemDataBound</strong> event of my outer ListView, I am doing this:</p> <pre><code>protected void grdAccounts_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.DataItem) { var dataItem = e.Item as ListViewDataItem; if (dataItem != null) { var parentID = ((BLL.Models.Account)dataItem.DataItem).AccountNumber; var sqlParts = (ObjectDataSource)e.Item.FindControl("dataSourceParticipants"); if (sqlParts != null) { var parameterParentID = sqlParts.SelectParameters[0]; parameterParentID.DefaultValue = parentID; } } } } </code></pre> <p>This works perfectly, it's important to clarify that everything above this line works 100%, all of the methods do exactly what I want them to do.</p> <p>I want to update my <strong>UpdateParticipantDetails</strong> method like so:</p> <pre><code> public bool UpdateParticipantDetails(Participant participant, string accountNumber) { return ParticipantManager.UpdateParticipantDetails(participant, accountNumber, AccountManager); } </code></pre> <p>I want to pass the same <strong>AccountNumber</strong> property into this method that I am using as the <strong>PropertyName</strong> for the <strong>ControlParameter</strong> in <strong>SelectParameters</strong> above.</p> <p>What do I need to add to the HTML of <strong>dataSourceParticipants</strong> to pass this new value into my Update method?</p> <p>I have tried this:</p> <pre><code>&lt;UpdateParameters&gt; &lt;asp:ControlParameter ControlID="grdAccounts" Name="participant"/&gt; &lt;asp:ControlParameter ControlID="grdAccounts" Name="accountNumber" PropertyName="SelectedDataKey.Values[AccountNumber]" Type="String"/&gt; &lt;/UpdateParameters&gt; </code></pre> <p>Resharper gives me this error:</p> <blockquote> <p>Incorrect number of parameters</p> </blockquote> <p>And when I try to update, I get the following execution time error:</p> <blockquote> <p>ObjectDataSource 'dataSourceParticipants' could not find a non-generic method 'UpdateParticipantDetails' that takes parameters of type 'PreScreening2.BLL.Models.Participant'.</p> </blockquote> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload