troubleshooting Question

DropDownList in ListView fed from a separate datasource?

Avatar of jn1480
jn1480Flag for United States of America asked on
ASP.NET
5 Comments1 Solution2725 ViewsLast Modified:
Our ListView control is bound to the Content table
In the InsertItem template (as well as the EditItem template eventually, etc...) we would like to populate a DropDownList control with the contents of the SiteMap table rather than using the standard textbox bound to the SiteMapID field in the Content Table.

However, when we run this page, we get the error "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control." in reference to the line: "<asp:DropDownList ID="ddl1" runat="server" DataSourceID="dsSiteMap" DataTextField="Title_Nav" DataValueField="ID" SelectedValue='<%# Bind("SiteMapID") %>'></asp:DropDownList>"

This kind of setup works perfectly when using a DetailsView...
What am I missing here?
<asp:SqlDataSource ID="dsContent" runat="server" 
        ConnectionString="<%$ ConnectionStrings:csButtermoonArts %>" 
        DeleteCommand="DELETE FROM [Content] WHERE [ID] = @ID" 
        InsertCommand="INSERT INTO [Content] ([SiteMapID], [LocationID], [SortORder], [Content], [Authorized], [DateTime_Create], [DateTime_Update], [AuthorID]) VALUES (@SiteMapID, @LocationID, @SortORder, @Content, @Authorized, @DateTime_Create, @DateTime_Update, @AuthorID)" 
        SelectCommand="SELECT [ID], [SiteMapID], [LocationID], [SortORder], [Content], [Authorized], [DateTime_Create], [DateTime_Update], [AuthorID] FROM [Content] WHERE ([SiteMapID] = @SiteMapID) ORDER BY [LocationID], [SortORder]" 
        UpdateCommand="UPDATE [Content] SET [SiteMapID] = @SiteMapID, [LocationID] = @LocationID, [SortORder] = @SortORder, [Content] = @Content, [Authorized] = @Authorized, [DateTime_Create] = @DateTime_Create, [DateTime_Update] = @DateTime_Update, [AuthorID] = @AuthorID WHERE [ID] = @ID">
        <SelectParameters>
            <asp:QueryStringParameter Name="SiteMapID" QueryStringField="SiteMapID" 
                Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="SiteMapID" Type="Int32" />
            <asp:Parameter Name="LocationID" Type="Int32" />
            <asp:Parameter Name="SortORder" Type="Int32" />
            <asp:Parameter Name="Content" Type="String" />
            <asp:Parameter Name="Authorized" Type="Boolean" />
            <asp:Parameter Name="DateTime_Create" Type="DateTime" />
            <asp:Parameter Name="DateTime_Update" Type="DateTime" />
            <asp:Parameter Name="AuthorID" Type="Int32" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="SiteMapID" Type="Int32" />
            <asp:Parameter Name="LocationID" Type="Int32" />
            <asp:Parameter Name="SortORder" Type="Int32" />
            <asp:Parameter Name="Content" Type="String" />
            <asp:Parameter Name="Authorized" Type="Boolean" />
            <asp:Parameter Name="DateTime_Create" Type="DateTime" />
            <asp:Parameter Name="DateTime_Update" Type="DateTime" />
            <asp:Parameter Name="AuthorID" Type="Int32" />
        </InsertParameters>
    </asp:SqlDataSource>
 
 
 
    <asp:SqlDataSource ID="dsSiteMap" runat="server" 
        ConnectionString="<%$ ConnectionStrings:csButtermoonArts %>" 
        SelectCommand="SELECT [ID], [SortOrder], [Title_Head], [Title_Nav], [Description], [Keywords], [URL], [Authorized], [DateTime_Create], [DateTime_Update], [AuthorID] FROM [SiteMap] ORDER BY [SortOrder], [Title_Nav]"></asp:SqlDataSource>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    <asp:ListView ID="ListView1" runat="server" DataSourceID="dsContent" 
        DataKeyNames="ID" InsertItemPosition="LastItem">
        <ItemTemplate>
            <span style="">
            LocationID:
            <asp:Label ID="LocationIDLabel" runat="server" 
                Text='<%# Eval("LocationID") %>' />
            <br />
            SortOrder:
            <asp:Label ID="SortORderLabel" runat="server" Text='<%# Eval("SortORder") %>' />
            <br />
            <asp:CheckBox ID="AuthorizedCheckBox" runat="server" 
                Checked='<%# Eval("Authorized") %>' Enabled="false" Text="Authorized" />
            <br />
            <asp:Label ID="ContentLabel" runat="server" Text='<%# Eval("Content") %>' />
            <br />
            <asp:LinkButton ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />&nbsp;
            <asp:LinkButton ID="DeleteButton" runat="server" CommandName="Delete" 
                Text="Delete" />
            <hr />
            </span>
        </ItemTemplate>
        <AlternatingItemTemplate>
            <span style="">
            LocationID:
            <asp:Label ID="LocationIDLabel" runat="server" 
                Text='<%# Eval("LocationID") %>' />
            <br />
            SortOrder:
            <asp:Label ID="SortORderLabel" runat="server" Text='<%# Eval("SortORder") %>' />
            <br />
            <asp:CheckBox ID="AuthorizedCheckBox" runat="server" 
                Checked='<%# Eval("Authorized") %>' Enabled="false" Text="Authorized" />
            <br />
            <asp:Label ID="ContentLabel" runat="server" Text='<%# Eval("Content") %>' />
            <br />
            <asp:LinkButton ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />&nbsp;
            <asp:LinkButton ID="DeleteButton" runat="server" CommandName="Delete" 
                Text="Delete" />
            <hr />
            </span>
        </AlternatingItemTemplate>
        <EmptyDataTemplate>
            <span>No data was returned.</span>
        </EmptyDataTemplate>
        <InsertItemTemplate>
            <span style="">
            Add new content:<br /><br />
            SiteMapID:
            <asp:DropDownList ID="ddl1" runat="server" DataSourceID="dsSiteMap" DataTextField="Title_Nav" DataValueField="ID" SelectedValue='<%# Bind("SiteMapID") %>'></asp:DropDownList>
            
 
            <br />
            LocationID:
            <asp:TextBox ID="LocationIDTextBox" runat="server" 
                Text='<%# Bind("LocationID") %>' />
            <br />
            SortORder:
            <asp:TextBox ID="SortORderTextBox" runat="server" 
                Text='<%# Bind("SortORder") %>' />
            <br />
            Content:
            <FCKeditorV2:FCKeditor ID="ContentTextBox" runat="server" BasePath="~/fckeditor/" Value='<%# Bind("Content")%>' Height="300" Width="535" ToolbarCanCollapse="true" ToolbarStartExpanded="true"></FCKeditorV2:FCKeditor>
            <br />
            <asp:CheckBox ID="AuthorizedCheckBox" runat="server" 
                Checked='<%# Bind("Authorized") %>' Text="Authorized" />
            <br />
            <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                Text="Insert" />
            <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                Text="Clear" />
            <br />
            <br />
            <hr />
            </span>
        </InsertItemTemplate>
        <LayoutTemplate>
            <div ID="itemPlaceholderContainer" runat="server" style="">
                <span ID="itemPlaceholder" runat="server" />
            </div>
            <div style="">
                <asp:DataPager PageSize="15" ID="DataPager1" runat="server">
                    <Fields>
                        <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                            ShowLastPageButton="True" />
                    </Fields>
                </asp:DataPager>
            </div>
        </LayoutTemplate>
        <EditItemTemplate>
            <span style="">ID:
            <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
            <br />
            SiteMapID:
            <asp:TextBox ID="SiteMapIDTextBox" runat="server" 
                Text='<%# Bind("SiteMapID") %>' />
            <br />
            LocationID:
            <asp:TextBox ID="LocationIDTextBox" runat="server" 
                Text='<%# Bind("LocationID") %>' />
            <br />
            SortORder:
            <asp:TextBox ID="SortORderTextBox" runat="server" 
                Text='<%# Bind("SortORder") %>' />
            <br />
            Content:
            <FCKeditorV2:FCKeditor ID="ContentTextBox" runat="server" BasePath="~/fckeditor/" Value='<%# Bind("Content")%>' Height="300" Width="535" ToolbarCanCollapse="true" ToolbarStartExpanded="true"></FCKeditorV2:FCKeditor>
            <br />
            <asp:CheckBox ID="AuthorizedCheckBox" runat="server" 
                Checked='<%# Bind("Authorized") %>' Text="Authorized" />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" 
                Text="Update"  />
            <asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" 
                Text="Cancel" />
            <br />
            <br />
            <hr />
            </span>
        </EditItemTemplate>
        <SelectedItemTemplate>
            <span style="">ID:
            <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
            <br />
            SiteMapID:
            <asp:Label ID="SiteMapIDLabel" runat="server" Text='<%# Eval("SiteMapID") %>' />
            <br />
            LocationID:
            <asp:Label ID="LocationIDLabel" runat="server" 
                Text='<%# Eval("LocationID") %>' />
            <br />
            SortORder:
            <asp:Label ID="SortORderLabel" runat="server" Text='<%# Eval("SortORder") %>' />
            <br />
            Content:
            <asp:Label ID="ContentLabel" runat="server" Text='<%# Eval("Content") %>' />
            <br />
            <asp:CheckBox ID="AuthorizedCheckBox" runat="server" 
                Checked='<%# Eval("Authorized") %>' Enabled="false" Text="Authorized" />
            <br />
            DateTime_Create:
            <asp:Label ID="DateTime_CreateLabel" runat="server" 
                Text='<%# Eval("DateTime_Create") %>' />
            <br />
            DateTime_Update:
            <asp:Label ID="DateTime_UpdateLabel" runat="server" 
                Text='<%# Eval("DateTime_Update") %>' />
            <br />
            AuthorID:
            <asp:Label ID="AuthorIDLabel" runat="server" Text='<%# Eval("AuthorID") %>' />
            <br />
            <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
            <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                Text="Delete" />
            <br />
            <br />
            </span>
        </SelectedItemTemplate>
    </asp:ListView>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros