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

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

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

    I've spent loads of time Googling to try to work this one out and I'm
    sure it's something obvious.

    I get an InvalidOperationException reading "Databinding methods such as
    Eval(), XPath(), and Bind() can only be used in the context of a
    databound control" when I start my page. Unless I'm missing something
    obvious, this is *not* the same issue as the "2-way databinding
    cascading lists" issue in
    [url]http://www.webswapp.com/codesamples/aspnet20/dependentlists/default.aspx[/url]
    (which is linked from everywhere; I kinda wish that were my problem ;o)

    I have a templated databound custom server control, that I've built
    with
    a great deal of help from the two articles by 4GuysFromRolla's Scott
    Mitchell ([url]http://masl.to/?S11823B6D[/url] and [url]http://masl.to/?P40821B6D[/url], both
    on msdn.microsoft.com).

    I don't seem to be able to use databinding syntax, however:

    <ItemTemplate>
    <asp:TableCell runat="server"><%# Eval("First")
    %></asp:TableCell>
    ...
    </ItemTemplate>

    bound to a List<Pair> gives me an exception:

    [InvalidOperationException: Databinding methods such as Eval(),
    XPath(),
    and Bind() can only be used in the context of a databound control.]
    System.Web.UI.Page.GetDataItem() +90
    System.Web.UI.TemplateControl.Eval(String expression) +110
    ASP.owentest_aspx.__DataBind__control8(Object sender, EventArgs e)
    in
    c:\Projects\Customisation\RedesignProtoTypeWeb\Owe ntest.aspx:13
    System.Web.UI.Control.OnDataBinding(EventArgs e) +80
    System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +198
    System.Web.UI.Control.DataBind() +12
    System.Web.UI.Control.DataBindChildren() +214
    System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +208
    System.Web.UI.Control.DataBind() +12
    System.Web.UI.Control.DataBindChildren() +214
    System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +208
    System.Web.UI.Control.DataBind() +12
    uSwitch.Web.UI.Lego.RepeatingInputRow.CreateItem(I nt32 rowIndex,
    Table container, Boolean useDataBinding, Object rowData) in

    C:\Projects\uSwitch.Web\UI.Lego\InputModule\Repeat ingInputRow.cs:361
    uSwitch.Web.UI.Lego.RepeatingInputRow.CreateContro lHierarchy(Boolean
    useDataBinding) in

    C:\Projects\uSwitch.Web\UI.Lego\InputModule\Repeat ingInputRow.cs:452
    uSwitch.Web.UI.Lego.RepeatingInputRow.DataBind() in

    C:\Projects\uSwitch.Web\UI.Lego\InputModule\Repeat ingInputRow.cs:643
    Owentest.Page_Load(Object sender, EventArgs e) in

    c:\Projects\Customisation\RedesignProtoTypeWeb\Owe ntest.aspx.cs:20
    System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object
    o, Object t, EventArgs e) +13
    System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object
    sender, EventArgs e) +45
    System.Web.UI.Control.OnLoad(EventArgs e) +80
    System.Web.UI.Control.LoadRecursive() +49
    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean
    includeStagesAfterAsyncPoint) +3716

    I don't get the exception if my databinding control is outside the
    table
    cell but, for a handful of other reasons, including that my
    ItemTemplate
    is being instantiated inside a TableRow, that won't work for me.

    Any ideas gratefully received, as I'm completely lost.


    Owen
    --
    Owen Blacker, London GB
    Say no to ID cards: [url]www.no2id.net[/url]
    Get your mits off my bits: [url]www.openrightsgroup.org[/url]
    --
    Those who would give up essential liberty to purchase a little
    temporary safety, deserve neither liberty nor safety -- Benjamin
    Franklin, 1759

    Owen Blacker Guest

  2. Similar Questions and Discussions

    1. Custom Templated Databound Control or derived control?
      Hi, I want to create a control that performs much like a datalist but I want more control over how the <ItemTemplate> contents is set out on the...
    2. Composite control delegating databound templated features to child <asp:repeater> control
      Hi Everybody, I'm creating a composite control in C# that basically renders a bunch of webcontrols such as <asp:Label />, <asp:Repeater />,...
    3. web Navigator Databound Control
      Hello, I Can not make this Navigator (Superexpert DataForm ) work on Oracle using the OLEDB part of it although the SQLDB works perfectly fine. ...
    4. Control derived from datagrid, problem with adding other control and databinding (VB)
      I all, my employer required me to add a bunch of control to a datagrid (such as a drop down list on top corner to select page size and prev, bunch...
    5. Eval and methods
      How do you do meta type stuff in Ruby? E.g. a_method = "to_str" an_attribute = "color" class Toad attr_accessor :color def initialize( c )...
  3. #2

    Default RE: Databinding methods such as Eval(), XPath(), and Bind() can only b

    Owen,

    Can you post the entire page code that causes this problem?
    --
    HTH,
    Phillip Williams
    [url]http://www.societopia.net[/url]
    [url]http://www.webswapp.com[/url]


    "Owen Blacker" wrote:
    > I've spent loads of time Googling to try to work this one out and I'm
    > sure it's something obvious.
    >
    > I get an InvalidOperationException reading "Databinding methods such as
    > Eval(), XPath(), and Bind() can only be used in the context of a
    > databound control" when I start my page. Unless I'm missing something
    > obvious, this is *not* the same issue as the "2-way databinding
    > cascading lists" issue in
    > [url]http://www.webswapp.com/codesamples/aspnet20/dependentlists/default.aspx[/url]
    > (which is linked from everywhere; I kinda wish that were my problem ;o)
    >
    > I have a templated databound custom server control, that I've built
    > with
    > a great deal of help from the two articles by 4GuysFromRolla's Scott
    > Mitchell ([url]http://masl.to/?S11823B6D[/url] and [url]http://masl.to/?P40821B6D[/url], both
    > on msdn.microsoft.com).
    >
    > I don't seem to be able to use databinding syntax, however:
    >
    > <ItemTemplate>
    > <asp:TableCell runat="server"><%# Eval("First")
    > %></asp:TableCell>
    > ...
    > </ItemTemplate>
    >
    > bound to a List<Pair> gives me an exception:
    >
    > [InvalidOperationException: Databinding methods such as Eval(),
    > XPath(),
    > and Bind() can only be used in the context of a databound control.]
    > System.Web.UI.Page.GetDataItem() +90
    > System.Web.UI.TemplateControl.Eval(String expression) +110
    > ASP.owentest_aspx.__DataBind__control8(Object sender, EventArgs e)
    > in
    > c:\Projects\Customisation\RedesignProtoTypeWeb\Owe ntest.aspx:13
    > System.Web.UI.Control.OnDataBinding(EventArgs e) +80
    > System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +198
    > System.Web.UI.Control.DataBind() +12
    > System.Web.UI.Control.DataBindChildren() +214
    > System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +208
    > System.Web.UI.Control.DataBind() +12
    > System.Web.UI.Control.DataBindChildren() +214
    > System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +208
    > System.Web.UI.Control.DataBind() +12
    > uSwitch.Web.UI.Lego.RepeatingInputRow.CreateItem(I nt32 rowIndex,
    > Table container, Boolean useDataBinding, Object rowData) in
    >
    > C:\Projects\uSwitch.Web\UI.Lego\InputModule\Repeat ingInputRow.cs:361
    > uSwitch.Web.UI.Lego.RepeatingInputRow.CreateContro lHierarchy(Boolean
    > useDataBinding) in
    >
    > C:\Projects\uSwitch.Web\UI.Lego\InputModule\Repeat ingInputRow.cs:452
    > uSwitch.Web.UI.Lego.RepeatingInputRow.DataBind() in
    >
    > C:\Projects\uSwitch.Web\UI.Lego\InputModule\Repeat ingInputRow.cs:643
    > Owentest.Page_Load(Object sender, EventArgs e) in
    >
    > c:\Projects\Customisation\RedesignProtoTypeWeb\Owe ntest.aspx.cs:20
    > System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object
    > o, Object t, EventArgs e) +13
    > System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object
    > sender, EventArgs e) +45
    > System.Web.UI.Control.OnLoad(EventArgs e) +80
    > System.Web.UI.Control.LoadRecursive() +49
    > System.Web.UI.Page.ProcessRequestMain(Boolean
    > includeStagesBeforeAsyncPoint, Boolean
    > includeStagesAfterAsyncPoint) +3716
    >
    > I don't get the exception if my databinding control is outside the
    > table
    > cell but, for a handful of other reasons, including that my
    > ItemTemplate
    > is being instantiated inside a TableRow, that won't work for me.
    >
    > Any ideas gratefully received, as I'm completely lost.
    >
    >
    > Owen
    > --
    > Owen Blacker, London GB
    > Say no to ID cards: [url]www.no2id.net[/url]
    > Get your mits off my bits: [url]www.openrightsgroup.org[/url]
    > --
    > Those who would give up essential liberty to purchase a little
    > temporary safety, deserve neither liberty nor safety -- Benjamin
    > Franklin, 1759
    >
    >
    Phillip Williams Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139