0

Hi experts

I have three tables

Section: sectionid (int), title (varchar)

Category: catid (int), title (varchar), sectionid (int)

Content: id (int), title (varchar), body (varchar), sectionid (int), catid (int), published (bit)

I build a formview for adding, updating and deleting a Content

in the EditItemTemplate I replaced the section and category Textbox with two DropDowLists

I want to filter the Category DropDownList when I change the Section DropDownList

This is my Formview: I only mentioned the needed fields.


<asp:FormView ID="FormView1" runat="server" DataKeyNames="id" DataSourceID="ContentDataSource">
<EditItemTemplate>

<table width="100%" dir="rtl">

<tr>
<td style="width: 25%" class="recordsTableHeaderTR">
Section
</td>
<td style="width: 50%" class="recordsTableDataTD">
<asp:DropDownList ID="ContentSectionDropDownList" runat="server" DataSourceID="ContentSection" DataTextField="title" DataValueField="id" Text='<%# Eval("sectionid") %>' Font-Names="Tahoma" Width="100%" AutoPostBack="true"></asp:DropDownList>
<asp:SqlDataSource ID="ContentSection" runat="server" ConnectionString="<%$ ConnectionStrings:mzinj %>"
SelectCommand="SELECT [id], [title] FROM [sections]"></asp:SqlDataSource>
</td> <td style="width: 25%">
<asp:RequiredFieldValidator ID="SectionIDRFV" runat="server" ControlToValidate="ContentSectionDropDownList"
Display="Dynamic" ErrorMessage="Select Section" SetFocusOnError="True">Select Section</asp:RequiredFieldValidator></td>
</tr>

<tr>
<td style="width: 25%" class="recordsTableHeaderTR">
Category
</td>
<td style="width: 50%" class="recordsTableDataTD"> <asp:DropDownList ID="ContentCategoryDropDownList" runat="server" DataSourceID="ContentCategory" DataTextField="title" DataValueField="id" Text='<%# Eval("catid") %>' Font-Names="Tahoma" Width="100%" AutoPostBack="true"></asp:DropDownList>
<asp:SqlDataSource ID="ContentCategory" runat="server" ConnectionString="<%$ ConnectionStrings:mzinj %>" SelectCommand="SELECT [id], [title] FROM [categories] WHERE ([section] = @section)">
<SelectParameters>
asp:ControlParameter ControlID="ContentSectionDropDownList" Name="section" PropertyName="SelectedValue"
Type="int64" />
</SelectParameters>


</asp:SqlDataSource> </td> <td style="width: 25%">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ContentCategoryDropDownList" Display="Dynamic" ErrorMessage="Select Category" SetFocusOnError="True">Select Category</asp:RequiredFieldValidator> </td>
</tr>


</table>

</EditItemTemplate>
</asp:FormView>

The Problem is: when I change the value of the Section DropDownList inorder to filer the items of Category DropDownList, I Have the following error message.

{

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

Line 136: </td>
Line 137: <td style="width: 50%">
Line 138: <asp:DropDownList ID="ContentCategoryDropDownList" runat="server" DataSourceID="ContentCategory" DataTextField="title" DataValueField="id" Text='<%# Eval("catid") %>' Font-Names="Tahoma" Width="100%" AutoPostBack="true"></asp:DropDownList>
Line 139:
Line 140: <asp:SqlDataSource ID="ContentCategory" runat="server" ConnectionString="<%$ ConnectionStrings:mzinj %>"


}


please any body can Help?

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by __avd
0

lastleave,

Welcome to the daniweb.

First of all you have to read sticky threads located at the top of each forum. These threads helps you to understand the rule - How to post your problems and how to use code tags?

Second, you have to post your ASP.NET question in ASP.Forum. This is a VB.NET forum.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.