The Control DataSource or (DataSourceID) is not set

2 posts, 0 answers
  1. Mohamed
    Mohamed avatar
    7 posts
    Member since:
    Oct 2012

    Posted 11 Apr 2013 Link to this post

    Hello,

    I've the following code to bind:

    var lstEmployees = employeeRepository.All.Select(employee => new { employee.Id, employee.Name });

    txtEmployee.DataSource = lstEmployees.ToList();

    txtEmployee.DataTextField = "Name";

    txtEmployee.DataValueField = "Id";

    txtEmployee.DataBind();

    This code is called in the Page_Load() event inside the

    if (!IsPostBack) block.

    This triggers the error "The Control DataSource or (DataSourceID) is not set" when I start typing into it.
    What I noticed is, when I move the binding code outside the if (!IsPostBack) block, it works correctly.

     

     

     

     

     

     

     

     

     

     

     

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Apr 2013 Link to this post

    Hi Mohamed,

    I was able to replicate the issue. On removing the !IsPostBack from the page load, it worked fine for me.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top