Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a dat
I have the following structure 2 combos, the 2nd dependant on the first - and when I change the first combo the pages refreshes with errorDatabinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Which i assume has something to do with the 2nd combo rebinding and breaking the binding of the FormView. Have seen this prob around but can find a solution..
Any ideas?
Nik
<
asp:FormViewID="frm"runat="server"DataSourceID="SqlDataSource1"DefaultMode="Edit"><EditItemTemplate><tr><td>Level1</td><td><asp:DropDownListrunat="server"id="cmbEntity"DataSourceID="sqlLevel1"DataTextField="Level1"DataValueField="Level1"SelectedValue='<%# Bind("Level1") %>'AutoPostBack="true"></asp:DropDownList></td></tr><tr><td>Level2</td><td><asp:DropDownListrunat="server"id="cmbLevel2"DataSourceID="sqlLevel2"DataTextField="Level2"DataValueField="Level2"SelectedValue='<%# Bind("Level2") %>'></asp:DropDownList></td></tr><
asp:SqlDataSourceID="sqlLevel1"runat="server"ConnectionString="<%$ ConnectionStrings:Database %>"SelectCommand="SELECT Level1 FROM Level1"></asp:SqlDataSource>
<asp:SqlDataSourceID="sqlLevel2"runat="server"ConnectionString="<%$ ConnectionStrings:Database%>"SelectCommand="SELECT Level2 FROM Level2 WHERE Level1 = @Level1"><SelectParameters><asp:ControlParameterName="Level1"ControlID="cmbLevel1"PropertyName="SelectedValue"/></SelectParameters></asp:SqlDataSource></EditItemTemplate></asp:FormView><asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:Database%>"UpdateCommand="z"/>
Hi,
I've found a simple solution to Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. Suppose you have these two dropdownlist controls each one into an edittemplate of a detailsview (the first with autopostback):
<EditItemTemplate><asp:DropDownList ID="drpCats" runat="server" AutoPostBack="True" DataSourceID="sqlDSCats" DataTextField="Categoria" DataValueField="CategoriaID" SelectedValue='<%# Bind("CategoriaID") %>'>
</asp:DropDownList><asp:SqlDataSource ID="sqlDSCats" runat="server" ConnectionString="<%$ ConnectionStrings:SQL2000_FinancialApp %>"SelectCommand="SELECT [CategoriaID], [Categoria] FROM [tbl_Categorias]"></asp:SqlDataSource></EditItemTemplate><EditItemTemplate><asp:DropDownList ID="drpProds" runat="server" DataSourceID="sqlDSProds" DataTextField="Producto" DataValueField="ProductoID" SelectedValue='<%# xx(DataBinder.Eval(Container.DataItem,"ProductoID")) %>' AppendDataBoundItems="False"></asp:DropDownList><asp:SqlDataSource ID="sqlDSProds" runat="server" ConnectionString="<%$ ConnectionStrings:SQL2000_FinancialApp %>"SelectCommand="SELECT [ProductoID], [Producto] FROM [tbl_Productos] WHERE ([CategoriaID] = @CategoriaID)"><SelectParameters><asp:ControlParameter ControlID="drpCats" Name="CategoriaID" PropertyName="SelectedValue"Type="Int64" /></SelectParameters></asp:SqlDataSource></EditItemTemplate>1. Note in the second dropdownlist the SelectedValue Property (<%# xx(.....)%>). "xx" is a function like this:
function xx(ByVal a) as string
return a
end function
2. Taking into account that the eval method is not for two way databinding in edit and insert templates, the DetailsView control doesn't understand that the second dropdownlist is a member field for update. In this sense, you need to manually add an entry to the e.values dictionary into the ItemUpdating event.
Protected Sub DetailsView1_ItemUpdating(.......)
Dim d1 As DropDownList = DetailsView1.FindControl("drpProds")e.NewValues("ProductoID") = d1.SelectedValue
End Sub
Thats all ! simple ! I've found other "over-coded" solutions but takes so long for a simple problem.
CFC2006
I'm being bewildered by the same problem for several days.
Would you pls give the detailed description and the source code of this part:
1. Note in the second dropdownlist the SelectedValue Property (<%# xx(.....)%>). "xx" is a function like this:
function xx(ByVal a) as string
return a
end function
Thank you Very much!