[英]Binding dbcontext to gridview and displaying data
我有一个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();
}
如何显示不包含来自数据库的列名的列。
例如,当我将autogeneratecolumns设置为“ true”时,它将显示数据库中的列名,但我想在该列中以不同的名称显示相同的数据。
因此,我想以某种方式屏蔽它,而不是VideoUrl(数据库列的名称),以便数据来自videourl,但它有另一个名称,例如“ URL”。
谢谢您的帮助!
您可以在RowDataBound事件中处理它
protected void ParentSelect_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[2].Text = "URL";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.