Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
125
Using Entity Framework as datasource
posted

Hi,

   I am trying to use Entity Framework as data source for the webdatagrid. Instead of using EntityDataSource directly, I want to separate out the data layer into a service class where I get the data as List and then bind it to the webdatagrid. Unfortunately, it's not working as well as I thought.  I've been using UltraWebGrid before but haven't used WebDataGrid before so I might be missing something...

 1. 2 columns "EntityState" and "EntityKey" shows up on the grid. I don't see these columns/properties in the entity framework classes when I inspect the list I used as datasource. Is it possible to exclude these columns from display and from editing?

  2. Where can I find good example use of Entity Framework for WebDataGrid?

Thanks!

=============
code-behind
=============

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
   {
      UsersService usersService = new UsersService();
      WebDataGrid1.DataSource = usersService.GetUsers();
       // usersService.GetUsers() returns List<Users> selectedUsers = usersQuery.ToList();
      WebDataGrid1.DataBind();
   }
}

===============
aspx
===============
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="400px" Width="95%"
            onrowadded="WebDataGrid1_RowAdded" onrowupdated="WebDataGrid1_RowUpdated">
            <Behaviors>
                <ig:EditingCore>
                    <Behaviors>
                        <ig:CellEditing>
                        </ig:CellEditing>
                        <ig:RowAdding Alignment="Top">
                            <EditModeActions EnableF2="False" EnableOnActive="True" />
                        </ig:RowAdding>
                    </Behaviors>
                </ig:EditingCore>
                <ig:Selection CellClickAction="Row" RowSelectType="Single">
                </ig:Selection>
                <ig:RowSelectors>
                </ig:RowSelectors>
                <ig:Sorting>
                </ig:Sorting>
            </Behaviors>
        </ig:WebDataGrid>

Parents
No Data
Reply
  • 33839
    Verified Answer
    posted

    Hi,

    I don't believe there is a page in our samples browser that shows binding to Entity Framework.

    But to answer your first question.  According to your grid definition, you are allowing the data grid to auto generate columns.  If you define the columns yourself in the Columns collection and set this property to false, you will not see any undesired columns. 

    regards,

    David Young

Children
No Data