I'm going mad for this problem... I've an user control that has a FormView for the insert operations and a GridView for all others.

In both controls I've a DropDownList as follow:

<asp:DropDownList ID="DropDownList" runat="server"
    DataSourceID="ObjectDataSource" 
    DataTextField="Text"
    SelectedValue='<%# Bind("Code") %>'
    DataValueField="Code"
    AppendDataBoundItems="True" Width="200px" />

The error in the subject comes if the DropDownList in the FormView is present, if I comment it the DropDownList in the GridView works perfectly! It binds in edit mode and updates the value with out any problem!

But they are the same and only the ID changes.

The funny thing is that I've also another page with the same controls it works...

Does someone has any idea?

Thank you

Some more details:

Without the SelectedValue property the page loads but when I try to insert a new data I get a null exeption

Other details:

<asp:Panel ID="PanelInsertPortfolio" runat="server">
    <asp:FormView ID="FormView" runat="server" DefaultMode="Insert" DataSourceID="ObjectDataSourceForm">
        <InsertItemTemplate>
            <asp:Table runat="server">
                <asp:TableHeaderRow>
                    <asp:TableHeaderCell Text="Column 1" />
                    <asp:TableHeaderCell Text="Column 2" />
                    <asp:TableHeaderCell Text="Column 3" />
                </asp:TableHeaderRow>
                <asp:TableRow>
                    <asp:TableCell>
                        <%-- TextBox with server side validators --%>
                    </asp:TableCell>
                    <asp:TableCell>
                        <%-- TextBox with server side validators --%>
                    </asp:TableCell>
                    <asp:TableCell>
                        <asp:DropDownList ID="DropDownList" runat="server" DataSourceID="ObjectDataSourceDropDownList" 
                            DataTextField="Name" SelectedValue='<%# Bind("Code") %>' DataValueField="Code" AppendDataBoundItems="True" Width="200px">                        
                        </asp:DropDownList>
                        <br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server"
                            ControlToValidate="DropDownList" ValidationGroup="ValGroup"
                            ErrorMessage="Required" Display="Dynamic" ForeColor="Red" />
                    </asp:TableCell>
                    <asp:TableCell>
                        <asp:ImageButton ID="ImageButton" runat="server" CausesValidation="True"
                            ValidationGroup="ValGroup" CommandName="Insert"
                            ImageUrl="Image.png" />
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>
        </InsertItemTemplate>
    </asp:FormView>
</asp:Panel>

<asp:ObjectDataSource ID="ObjectDataSourceDropDownList" runat="server" SelectMethod="GetDataByName"
    TypeName="BLProject.BusinessLogic, BLProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1dd7d67e2859f7d9">
</asp:ObjectDataSource>

The FormView has been binded to another ObjectDataSource. The user control goes on SharePoint 2013.

1

There are 1 answers

0
chenny On BEST ANSWER

I tried to put another ObjectDataSource only for the insert operations and, I don't know why, it worked!