locked
ObjectDataSource Selected Event Raised Twice . . . Why? RRS feed

  • Question

  • User435566049 posted

    I have a page that contains at least two ObjectDataSources, one that displays the details of a record (sourceRecord), and one that contains a list of categories (sourceCategories).  I have a FormView that uses sourceRecord as its data source.  Inside the FormView's EditItemTemplate, there is a DropDownList that uses sourceCategories as its datasource.

    I use the Selected event for both of these ObjectDataSources in my code.  For reasons I cannot understand, the Selected event for sourceRecord is only raised once, but the Selected event for sourceCategories is raised twice.

    Here is the code for the two ObjectDataSources:

    <asp:ObjectDataSource ID="sourceRecord" runat="server" 
        SelectMethod="GetGraybookRecordByID" 
        TypeName="AFATempeDB.GraybookComponent.GraybookDB" 
        onselected="sourceGraybookDocument_Selected" 
        UpdateMethod="UpdateGraybookRecord" 
        OldValuesParameterFormatString="original_{0}">
    
        <UpdateParameters>
        ...               
        </UpdateParameters>
    
        <SelectParameters>
            <asp:QueryStringParameter DefaultValue="0" Name="record_id" 
                QueryStringField="DocID" Type="Int32" />
        </SelectParameters>
                
    </asp:ObjectDataSource>
        
    <asp:ObjectDataSource ID="sourceCategories" runat="server" 
        SelectMethod="GetAFSDocumentList" 
        TypeName="AFATempeDB.AFSDocumentsComponent.AFSDocumentsDB" 
        onselected="sourceAFSDocuments_Selected">
                
        <SelectParameters>
            <asp:ControlParameter ControlID="FormView1$chkWIUGRD_Fletcher" DefaultValue="false" 
                Name="wiugrd_fletcher" PropertyName="Checked" Type="Boolean" />
        </SelectParameters>
                
    </asp:ObjectDataSource>

    Can anyone explain why the Selected event is being raised twice and what I can do to fix it?

    Tuesday, May 31, 2011 2:09 PM

Answers

  • User3866881 posted

    Hello:)

    It seems that you've put the ObjectDataSource outside the FormView, and you want to bind the Dropdownlist with the ObjectDataSource (because I see your ControlId is FormView1$chkWIUGRD_Fletcher).

    I guess you can try to put the ObjectDataSource inside the ItemTemplate or EditTemplate inside the FormView to bind to the Dropdownlist.

    Thx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 1, 2011 10:46 PM