简体   繁体   中英

ASP.NET databound dropodownlist set value with jQuery

I'm trying to select the value of a DropDownList of a FormView through jQuery. The code I'm using is not working but I cannot understand why:

$("input[id$='_ddlwidget']").val(_data[0]);

Debugging it shows that the line is executed without problem but the DropDownList item is not changed.

The DropDownList is defined in this way:

<asp:FormView
   ID="_fvData"
   runat="server"
   DataKeyNames="id"
   DataSourceID="_sdsTable2"
   DefaultMode="Insert" Width="100%">
   <InsertItemTemplate>
    <asp:DropDownList ID="_ddlwidget" runat="server" DataSourceID="_sdsTable1"
        DataTextField="text_field1" DataValueField="text_field2"
        AppendDataBoundItems="true" SelectedValue='<%#Bind("_field2")%>'>
   </InsertItemTemplate>
</asp:FormView

Assuming data[0] is a valid option for that DropDownList, just use the normal jQuery id selector :

$('#_ddlwidget').val(_data[0]);

That should work just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM