[英]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.