【问题标题】:Binding dbcontext to gridview and displaying data将dbcontext绑定到gridview并显示数据
【发布时间】:2015-01-01 18:39:57
【问题描述】:

我有一个网格视图:

  <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(db 列的名称),以便数据来自 videourl,但它有另一个名称,如“URL”。

感谢您的帮助!

【问题讨论】:

    标签: c# entity-framework aspxgridview


    【解决方案1】:

    你可以在 RowDataBound 事件上处理它

    protected void ParentSelect_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
        if (e.Row.RowType == DataControlRowType.Header) 
        { 
            e.Row.Cells[2].Text = "URL"; 
        } 
    }
    

    【讨论】:

      猜你喜欢
      • 2015-02-28
      • 1970-01-01
      • 2013-04-10
      • 1970-01-01
      • 2013-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      相关资源
      最近更新 更多