0

请帮忙,因为我是 C# 的新手

我面临以下错误

“DataBinding:‘Sherserve.CustomTypeLayer.EmployeeLeave’不包含名为‘empId’的属性”

这是我的代码:

protected void Button1_Click(object sender, EventArgs e)
{
    LMSManager leavestatus = new LMSManager();
    int emplid = Convert.ToInt32(Session["EmployeeID"]);
    List<EmployeeLeave> leaverecord = leavestatus.GetLeaveRecord(emplid);

    GridView1.DataSource = leaverecord;
    GridView1.DataBind();
}

这是 EmployeeLeave :

public class EmployeeLeave
{
    public LeaveReason LeaveType { get; set; }
    public int EmployeeId { get; set; }
    public DateTime DateFrom { get; set; }
    public DateTime DateTo { get; set; }
    public string Reason { get; set; }
}

这是 aspx :

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True"
  PageSize="3" OnPageIndexChanging="GridView1_PageIndexchanging" CellPadding="4"
  ForeColor="#333333" Height="16px" 
  Style="margin-bottom: 0px; margin-right: 0px;">
  <%-- DataSourceID="SqlDataSource1"--%>
    <AlternatingRowStyle BackColor="White" />
    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
    <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
    <SortedAscendingCellStyle BackColor="#FDF5AC" />
    <SortedAscendingHeaderStyle BackColor="#4D0000" />
    <SortedDescendingCellStyle BackColor="#FCF6C0" />
    <SortedDescendingHeaderStyle BackColor="#820000" />

    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="lblEmpId" runat="server" Text='<%#Eval("empId")%>'/>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="lblLeaveType" runat="server" Text='<%#Eval("LeaveType") %>'/>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="lblempid" runat="server" Text='<%#Eval("EmployeeId") %>'/>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="lblDateFrm" runat="server" Text='<%#Eval("DateFrom") %>'/>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="lblDateTo" runat="server" Text='<%#Eval("DateTo") %>'/>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="lblRsn" runat="server" Text='<%#Eval("Reason") %>'/>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
4

1 回答 1

2

看起来您的数据绑定指的是实际调用empId的字段。EmployeeLeaveEmployeeId

尝试改变

<ItemTemplate>
    <asp:Label ID="lblEmpId" runat="server" Text='<%#Eval("empId")%>'></asp:Label>
</ItemTemplate>

<ItemTemplate>
    <asp:Label ID="lblEmpId" runat="server" Text='<%#Eval("EmployeeId")%>'></asp:Label>
</ItemTemplate>
于 2012-08-31T10:41:19.863 回答