[英]Set TextBox Based on Value From DropdownList (populated by database) on initial Load
我在初始加载时从下拉菜单设置货币texboxt时遇到问题,它仅在下拉菜单更改后才更改,该下拉菜单由使用cbe代码隐藏的数据库填充,对于下拉菜单更改,我使用ajax
好吧,这是代码下拉列表
<asp:DropDownList ID="ddlPaymentCurrency" CssClass="form-control" runat="server" onblur="showCRate2()" onChange="showCRate2()" onkeyup="showCRate2()"></asp:DropDownList>
和功能ddlPaymentCurrency onchange
function showCRate2(obj) {
this.curr();
var selectedCurrency = $('#<%=ddlPaymentCurrency.ClientID%>').val();
console.log(selectedCurrency);
if (selectedCurrency != null && selectedCurrency != "") {
$.ajax({
type: "POST",
url: "TopUp.aspx/getCurr",
data: '{id:"' + selectedCurrency + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var o = response.d;
$('#<%=hfCurrencyRate.ClientID%>').val(o.RateBuy);
$('#<%=hfCR.ClientID%>').val(o.RateBuy);
},
error: function (response) {
alert('error')
}
});
}
}
和网络方法
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static MukyaServiceReference.CurrRate getCurr(int id)
{
var CR = client.GetCurrRates(id);
return CR;
}
有人可以帮忙吗?
您可以根据页面加载时的下拉列表值或在前端使用JQuery来设置文本框的值
这样便可以在文本框中选择下拉菜单的第一项的值。 使用jQuery。
$(document).ready(function(){
$('#ddlPaymentCurrency').val( $('#ddlPaymentCurrency option:first-child').val() );
$('#yourTextBoxId').val($('#ddlPaymentCurrency').val());
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.