C# GridView,它必须是IListSource、IEnumerable或IDataSource

C# GridView,它必须是IListSource、IEnumerable或IDataSource,c#,asp.net,entity-framework,gridview,C#,Asp.net,Entity Framework,Gridview,这是我的源代码 <asp:GridView ID="gveducationInfo" CssClass="footable" runat="server" AutoGenerateColumns="false" Style="max-width: 600px" ShowHeaderWhenEmpty="true" DataKeyNames="Education_ID" OnRowCommand="gveducationInfo_RowCommand"> <Columns

这是我的源代码

<asp:GridView ID="gveducationInfo" CssClass="footable" runat="server" AutoGenerateColumns="false" Style="max-width: 600px" ShowHeaderWhenEmpty="true" DataKeyNames="Education_ID" OnRowCommand="gveducationInfo_RowCommand">
    <Columns>
        <asp:BoundField DataField="Education_ID" HeaderText="" ItemStyle-CssClass="hiddenColumn" HeaderStyle-CssClass="hiddenColumn" />
        <asp:BoundField DataField="Degree_Type" />
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:BoundField DataField="Year_Of_Passing" HeaderText="Year Of Passing" />
        <asp:BoundField DataField="Institute_Name" HeaderText="Institute Name" />
        <asp:BoundField DataField="State_ID" HeaderText="State" />
        <asp:BoundField DataField="City_ID" HeaderText="City" />
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <%--<asp:BoundField DataField="Notes" HeaderText="Notes" />--%>
        <asp:ButtonField ButtonType="Image" ImageUrl="~/images/edit16.png" CommandName="EditRow" ItemStyle-CssClass="align-center" />
        <asp:ButtonField ButtonType="Image" ImageUrl="~/images/delete16.png" CommandName="DeleteRow" ItemStyle-CssClass="align-center" />
    </Columns>
</asp:GridView>
这是我的实体框架数据库代码

public IList<Education_Info> GetEduInfo()
{
    using (Data.ATSEntities dc = new Data.ATSEntities())
    {
        var lsteducationinfo = dc.Education_Info.ToList();
        return lsteducationinfo;
    }
}
public IList GetEduInfo()
{
使用(Data.atsenties dc=new Data.atsenties())
{
var lsteducationinfo=dc.Education_Info.ToList();
返回信息;
}
}
当我在网页中填写详细信息并单击“保存页面”时,我需要获取用户在gridview中输入的最后一条记录,但忽略错误

数据源是无效的类型。它必须是IListSource, IEnumerable或IDataSource

有人知道如何驾驭它吗?

调用
Last()
问题在于:

gveducationInfo.DataSource = ats.GetEduInfo().Last();
删除对
Last()
的调用,如下所示:

gveducationInfo.DataSource = ats.GetEduInfo();
为什么?

GetEduInfo
方法返回一个
IList
,而
IList
实现了
IEnumerable
,它将与
数据源一起工作。但是,当调用
Last()
时,您不再传递
IEnumerable
,而是传递序列的最后一项,这将不起作用

如果要将单个项绑定到
数据源
,则需要将其包装为
IEnumerable
。您可以使用以下任意答案,例如将单个项包装到数组中:

gveducationInfo.DataSource = new Education_Info[] {ats.GetEduInfo().Last()};
调用
Last()
问题在于:

gveducationInfo.DataSource = ats.GetEduInfo().Last();
删除对
Last()
的调用,如下所示:

gveducationInfo.DataSource = ats.GetEduInfo();
为什么?

GetEduInfo
方法返回一个
IList
,而
IList
实现了
IEnumerable
,它将与
数据源一起工作。但是,当调用
Last()
时,您不再传递
IEnumerable
,而是传递序列的最后一项,这将不起作用

如果要将单个项绑定到
数据源
,则需要将其包装为
IEnumerable
。您可以使用以下任意答案,例如将单个项包装到数组中:

gveducationInfo.DataSource = new Education_Info[] {ats.GetEduInfo().Last()};

我删除了Last(),但我在网页的网格中得到了完整的表,但我只需要用户输入的最后一条记录。这可能吗@肖恩Luttin@KarthikeyanMuthukumaran对这是可能的。请参阅编辑。非常感谢@Shaun Luttini删除了最后一条(),但我在网页的网格中获得了完整的表格,但我只需要用户输入的最后一条记录。这可能吗@肖恩Luttin@KarthikeyanMuthukumaran对这是可能的。见编辑。非常感谢@Shaun Luttin