我用Json编写了我的代码
function OnGetNotes(index) {
proxyNotes.invoke("SearchBranchesByBankID",{ "request":{"BankID": index}
}, OnGetNotesComplete, OnError);
}
function OnGetNotesComplete(result) {
var obj = jQuery.parseJSON(result);
var notes = obj.Branches;
if (notes.length > 0) {
for (var i = 0; i < notes.length; i++) {
var item = notes[i];
$("#<%=cboBranch.ClientID%>").append($("<option></option>").val(notes[i].ID).html(notes[i].BranchName));
}
这是我的 c# 中的代码,当我按下添加按钮时,我无法访问分支下拉列表的选定值
protected void btnSaveBank_Click(object sender, EventArgs e)
{
if (int.Parse(cboBank.SelectedValue) != -1)
{
int bankID = int.Parse(cboBank.SelectedValue);
string bankName = cboBank.SelectedItem.Text;
int branchID = int.Parse(cboBranch.SelectedValue);//this have no value at all
string branchName = cboBranch.SelectedItem.Text;//and also this
string accName = txtAccountName.Text;
string accNo = txtAccountNumber.Text;
DateTime tdate = UtilityHelper.ConvertToDateTime(txtToDateBank.Text);
DateTime fdate = UtilityHelper.ConvertToDateTime(txtFromDateBank.Text);
AddContractorBankAccountDetails(bankID, bankName, 1, "branch one", accName, accNo, tdate, fdate);
}
else
{
alertBoxBank.Visible = true;
}
}
谢谢
int bankID = int.Parse(cboBank.SelectedValue.toString());
最后使用字符串...或者您也可以通过以下方式执行此操作
int bankID = int。Parse(cboBank.SelectedItem.toString());
这将取决于您的物品价值。