2015-01-01 2 views
1

난있는 gridview 있습니다바인딩 dbcontext는

<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 열의 이름) 대신 데이터를 비디오 마스크에서 가져오고 싶지만 "URL"과 같은 다른 이름이 있습니다.

도움 주셔서 감사합니다.

답변

0

당신은 RowDataBound 이벤트를 처리 할 수 ​​

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