Problem with Details view

C

Cirene

I have a detailsview control. In theInsertItemTemplate I have 2 cascade
dropdownlists (for category and subcategory). For the 2nd one (subcategory)
I tried to do a databind to a field but I get this error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control.

Any ideas why? Here's part of the html code...

<InsertItemTemplate>
<table class="style3">
<tr>
<td class="style4">
Category:</td>
<td>
<asp:DropDownList ID="ddlCatInsert"
runat="server" AutoPostBack="True"
DataSourceID="sdsCategories"
DataTextField="Category" DataValueField="Id"
</asp:DropDownList>
<asp:SqlDataSource ID="sdsCategories"
runat="server"
ConnectionString="<%$
ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM
[classifiedCategories] ORDER BY [Category]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="style4">
Subcategory:</td>
<td>
<asp:SqlDataSource ID="sdsSubCategories"
runat="server"
ConnectionString="<%$
ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM
[classifiedSubcategories] WHERE ([CategoryId] = @CategoryId)">
<SelectParameters>
<asp:ControlParameter
ControlID="ddlCatInsert" Name="CategoryId"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1"
runat="server"
DataSourceID="sdsSubCategories"
DataTextField="SubCategory" DataValueField="Id"
SelectedValue='<%# Bind("SubcategoryId")
%>'>
</asp:DropDownList>
</td>
</tr>
 
C

Cirene

i mean FORMVIEW :)

Cirene said:
I have a detailsview control. In theInsertItemTemplate I have 2 cascade
dropdownlists (for category and subcategory). For the 2nd one
(subcategory) I tried to do a databind to a field but I get this error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used
in the context of a databound control.

Any ideas why? Here's part of the html code...

<InsertItemTemplate>
<table class="style3">
<tr>
<td class="style4">
Category:</td>
<td>
<asp:DropDownList ID="ddlCatInsert"
runat="server" AutoPostBack="True"
DataSourceID="sdsCategories"
DataTextField="Category" DataValueField="Id"</asp:DropDownList>
<asp:SqlDataSource ID="sdsCategories"
runat="server"
ConnectionString="<%$
ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM
[classifiedCategories] ORDER BY [Category]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="style4">
Subcategory:</td>
<td>
<asp:SqlDataSource ID="sdsSubCategories"
runat="server"
ConnectionString="<%$
ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM
[classifiedSubcategories] WHERE ([CategoryId] = @CategoryId)">
<SelectParameters>
<asp:ControlParameter
ControlID="ddlCatInsert" Name="CategoryId"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1"
runat="server"
DataSourceID="sdsSubCategories"
DataTextField="SubCategory" DataValueField="Id"
SelectedValue='<%# Bind("SubcategoryId")
%>'>
</asp:DropDownList>
</td>
</tr>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top