Reputation: 2437
I have a dropdownlist with data being bound dynamically this way at Page_Load:
<asp:DropDownList ID="ddlSet" DataTextField="Title" DataValueField="PKSetId" runat="server"
AppendDataBoundItems="true" ng-model="SetId"></asp:DropDownList>
The rendered html is :
<select id="cpContent_ddlSet" ng-model="SetId">
<option value="? undefined:undefined ?"></option>
<option value="3">Test3</option>
</select>
The option Test3 should be selected by default when the page loads, but this isn't happening. I would have set $scope.SetId=3
, but don't know this value before hand.
I see similar questions here but the dropdownlists are data bound the angular way, where you can easily set the selected item from $scope.
How to tackle this.
Upvotes: 1
Views: 57
Reputation: 3104
Either you build a server side ASP application or you build a client side Angular application, but don't mix the 2 technologies.
Let Angular do the whole frontend logic and rendering and the ASP will just provide the REST services.
See Angulars Select for an example how to preselect a dropdown value.
Upvotes: 2
Reputation: 638
You cannot do this in this way.
I suggest to add option at first place with such as:
<option value="" disabled ng-selected> Make your choice:
Upvotes: 1