通过绑定字段将 DBCONTEXT 绑定到 gridview

本文关键字:绑定 gridview DBCONTEXT 字段 | 更新日期: 2023-09-27 18:36:01

我有一个网格视图:

 <asp:GridView ID="ParentSelect" runat="server" AutoGenerateColumns="false" OnRowCommand="ParentSelect_RowCommand" OnRowCreated="ParentSelect_RowCreated" emptydatatext="Please Submit A Clip. C'mon dude." ShowHeaderWhenEmpty="true" HorizontalAlign="Center" Width="600" CssClass= "table table-striped table-bordered table-condensed">
<HeaderStyle BorderColor="Black"   />
<Columns>
    <asp:BoundField DataField ="dbContext.Mains.VideoUrl" HeaderText="Title" Visible="false" />
</Columns>
      </asp:GridView>

并且我已经绑定了我的数据库上下文:

protected void LoadGrid()
{
    ParentSelect.DataSource = dbContext.Mains.ToList(); 
    ParentSelect.DataBind();
}

我想通过边界字段在网格视图上显示数据库中的数据。我怎样才能做到这一点?请,谢谢。

通过绑定字段将 DBCONTEXT 绑定到 gridview

它很简单:

<asp:BoundField DataField ="VideoUrl" HeaderText="Title" />