1

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.

1
  • 1
    Mixing them is not good. Doing a quick search on selecteditem for dropdownlist shows different way of setting (selecting) an item in a DropDownList. My suggestion, set the selected item in Page_Load. For example: {list}.SelectedValue = theValue.ToString(). Commented Jul 2, 2015 at 8:22

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.