【发布时间】:2020-02-29 09:04:27
【问题描述】:
加载下拉列表,当我在城市表中添加数据时,下拉列表将加载到页面上而不加载页面
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
DataSourceID="SqlDataSource1" onchange="showhideDiv()"
DataTextField="Name" DataValueField="Name"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Name] FROM [City]"></asp:SqlDataSource>
<script type="text/javascript">
$(document).ready(function () {
$('#btnAddCity').click(function () {
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: '2tabledataenterusing1page.aspx/insert_data',
data: "{'Name':'" + document.getElementById('txtaddcity').value + "'}",
success: function (response) {
$('#txtaddcity').val('');
$('#MainContent_DropDownList1').Onload();
alert("Record Has been Saved in Database");
},
error: function () {
console.log('there is some error');
}
});
});
});
</script>
【问题讨论】: