通过boundfield将DBCONTEXT绑定到gridview

时间:2015-01-02 13:52:33

标签: c# asp.net entity-framework gridview

我有一个gridview:

 <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>

我绑定了我的DBCONTEXT:

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

我想通过BoundField在gridview上显示数据库中的数据。我怎么能做到这一点? 拜托,谢谢你。

1 个答案:

答案 0 :(得分:0)

这很简单:

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