This is a migrated thread and some comments may be shown as answers.

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

3 Answers 1057 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 23 Dec 2008, 09:34 AM
I have a RadGrid which lists addresses. I have configured it to popup during edit, in which there are 2 dropdown lists, for country and for province - the first dropdown  being set to AutoPostBack=true, so that any change there, will also change the list of provinces available.
But when I change the country selection, 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 on how to get around this problem?

=================
                                   <td>
                                    Country:</td>
                                <td>
    <asp:ObjectDataSource ID="obCountry" runat="server"
        SelectMethod="GetAllCountries"
        TypeName="CNH.CountryController">
    </asp:ObjectDataSource>
                                <asp:DropDownList ID="cbCountry" runat="server" AutoPostBack="True"  SelectedValue='<%# Bind("intCountry") %>'
                                    DataSourceID="obCountry" DataTextField="txtName"
                                    DataValueField="intcountry">
                                </asp:DropDownList>   

</td>                           
                                                               
                             
 
                            </tr>                                                                                 
                            <tr>
                                <td>
                                    Province:</td>
                                <td>
                                    <asp:ObjectDataSource ID="obProv" runat="server"
                                        SelectMethod="GetAllProvinces"
                                        TypeName="CNH.ProvStateController" >
                                        <SelectParameters>
                                            <asp:ControlParameter ControlID="cbCountry"
                                                Name="intCountry" PropertyName="SelectedValue" Type="Int32" />
                                        </SelectParameters>
                                    </asp:ObjectDataSource>                               
                                     <asp:DropDownList ID="cbProv" runat="server"
                                        DataSourceID="obProv" DataTextField="txtname"  SelectedValue='<%# Bind("intprovstate") %>'
                                        DataValueField="intprovstate">
                                    </asp:DropDownList>
                                   
                                </td>

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 23 Dec 2008, 10:49 AM
Hello Eric,

I found an interesting discussion about this error in Microsoft Connect:
Rebinding a DropDownList with a SelectedValue AFTER a PostBack (when the dataObject is empty) causes errors

Let us know whether this helps.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Dec 2008, 11:03 AM
Hello Eric,

Try setting the selected value as shown in the code below and see if it helps:
aspx:
<asp:DropDownList ID="cbCountry" runat="server" AutoPostBack="True" SelectedValue='<%# DataBinder.Eval(Container.DataItem,"intCountry") %>'  DataSourceID="obCountry" DataTextField="txtName" DataValueField="intcountry"
</asp:DropDownList>     

Thanks
Princy.




0
Eric
Top achievements
Rank 1
answered on 28 Dec 2008, 10:34 PM
Hi Princy, I'm still getting the same error...
Tags
Grid
Asked by
Eric
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Princy
Top achievements
Rank 2
Eric
Top achievements
Rank 1
Share this question
or