How can I fix "Data binding methods such as Eval (), XPath (), and Bind () can only be used in the context of database management."

I have a custom control (ascx) to which I have added two public properties: RequestTypeId and GroupId. Both have an attribute Bindable(True)

.

In my aspx page I have a ListView and in the ItemTemplate I put a link to the control like:

    <asp:ListView ID="lv" runat="server">
        <LayoutTemplate>
            <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
        </LayoutTemplate>
        <ItemTemplate>
           <tr>
              <td>
                 <ctrl:ServiceTypeGroup id="ctrlServiceTypes" runat="server" RequestTypeId="<%#RequestType.RequestTypeId%>" GroupId='<%#Eval("Id")%>' />
              </td>
           </tr>
        </ItemTemplate>
    </asp:ListView>

      

The RequestTypeId setting works fine. Troubleshooting the GroupId error occurs with the following error:

"Data binding methods such as Eval (), XPath () and Bind () can only be used in the context of database management."

What do I need to do with my custom control code to bind an Eval () expression to one of its properties? Or is it impossible?

+2


a source to share


1 answer


There are some properties, such as [Bindable (true)], that you can expose to custom controls.

Have you added this to the properties in question? It will look something like this:

[Bindable(true)]
public int RequestTypeID { get; set; }

[Bindable(true)]
public int GroupID { get; set; }

      

You need the following:



using System.ComponentModel;

      

Additional Information:

0


a source







All Articles