In my ASP.NET 4.5 WebForms app, In my ListView I am trying to bind DropDownList, but am not able to do it. Actually, the Model that is bind to ListView, has a Property of UnitdirectionId & on Edit & Insert Templates' I want to show the dropdown of all UnitDirection table.
Here is my EditTempalte :
DataTextField="DirectionTitle" DataValueField="UnitDirectionId"
SelectMethod="GetUnitDirections">
In Code behind,
public IQueryable GetUnitDirections()
{
return _db.UnitDirections;
}
Now, the Model of LsitView has the proerpty as follows :
[Display(Name= "Unit Direction")]
public int UnitDirectionId { get; set; }
[ForeignKey("UnitDirectionId")]
public virtual UnitDirection UnitDirection { get; set; }
Now, the UnitDirection Model :
public class UnitDirection
{
[ScaffoldColumn(false)]
public int UnitDirectionId { get; set; }
[Required]
[Display]
public string DirectionTitle { get; set; }
}
In db the UnitDirection table has 3 items.
With the above drop down, I believe I should atleast get list of all UnitDirection in drop down. But on that I am getting error. Then comes to set the selected item in Edit Template.
Can you please help me identify why I am getting this error ??
Any help is highly appreciated.
Thanks
TerryPosted Apr 1, 2015, 12:24 PM
Sharing my answer, so it can be helpful to others facing similar problem.
The solution was in webconfig ConnectionString. I added MultipleActiveResultSets :
Integrated Security=True;MultipleActiveResultSets=true
in the connectionString and things worked.
The issue was, DB was already engaged in retrieving/accessing data in Edit/Insert model, hence it wasn't allowing to run other query while it was busy in an already existing resultset.