views:

56

answers:

0

Hi there,

I am getting the following error, Using asp.net and nHibernate.

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

I have this listview

<asp:ListView ID="CurrentHourList" runat="server" ItemPlaceholderID="itemPlaceholder">
                <LayoutTemplate>
                    <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                </LayoutTemplate>
                <ItemTemplate>
                    <asp:ImageButton ID="DeleteDateButton" CausesValidation="false" runat="server" CommandName="Delete"
                        ImageUrl="img/delete.png" />
                    &nbsp; <span style="display: none">
                        <asp:Label ID="Id" runat="server" Text='<%# Eval("Id") %>'></asp:Label></span>
                    <asp:Label ID="Date" Text='<%# Eval("Date", "{0:dd MMM yyyy}") %>' runat="server"></asp:Label>
                    <asp:DropDownList ID="MedicalType" runat="server" SelectedValue='<%# Eval("MedicalType.Id") %>'>
                        <asp:ListItem Text="Paid" Value="1"></asp:ListItem>
                        <asp:ListItem Text="Unpaid" Value="2"></asp:ListItem>
                        <asp:ListItem Text="Special" Value="3"></asp:ListItem>
                    </asp:DropDownList>
                    Half-Day:<asp:CheckBox ID="HalfDay" runat="server" Checked='<%# Eval("IsHalfDay") %>' />
                    <br />
                </ItemTemplate>
            </asp:ListView>

and this in my code behind

private void BindData(string id)
    {
        MedLeaveHelper = new MedicalLeaveHelper();
        DTO.MedLeaveDTO dto = MedLeaveHelper.GetMedicalRequest(id);
        if (dto != null)
        {
            EnableForm();
            this.RequestId.Text = dto.Id.ToString();
            this.ddlEmployeeName.SelectedItem.Text = dto.User;
            this.Note.Text = dto.Note;

            this.CurrentHourList.DataSource = MedLeaveHelper.MakeMedicalDays(id);      
            this.CurrentHourList.DataBind();

        }

MakeMedicalDays(id) simply looks like this. MedicalDays is a IList

internal IEnumerable MakeMedicalDays(string id)
    {
        int theId = 0;
        if (int.TryParse(id, out theId))
        {
            MedicalRequest r = MedicalRequest.Get(theId);
            return r.MedicalDays;
        }
        return null;
    }

When I get to the DataBind() call the error shows up. I've poked around on the tubes but nothing concrete is jumping out at me. I've tried changing the syntax to something like this

DataBinder.Eval(Container.DataItem,"id")

and the error goes away but no data makes it into my ListView either.

as I understand it DataBinder.Eval uses reflection to determine my datatype, but I am not sure how to troubleshoot this issue. Any help you could provide would be great.

Thanks Jim