如何使用ajax绑定项目时获取选定的值 [英] How to get selected value when items binded with ajax

查看:49
本文介绍了如何使用ajax绑定项目时获取选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用jquery ajax()从数据库绑定dropdownlist项目。但问题是我无法访问buttonClick中的dropdownlist选择值代码背后的事件。



任何人都可以帮助我,当列表项与$ .ajax绑定时如何获得选定的值()



请找代码:

Hi ,

I am binding dropdownlist items from database using jquery ajax().But the problem is i'm unable to access the dropdownlist selected value in buttonClick event at code behind.

Can any one help me, how to get selected value when listitems binded with $.ajax()

please find code:

.aspx apge

<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/BindDatatoDropdown",
data: "{}",
dataType: "json",
success: function(data) {
$.each(data.d, function(key, value) {
$("#ddlCountry").append($("<option></option>").val(value.CountryId).html(value.CountryName));
});
},
error: function(result) {
alert("Error");
}
});
});
</script>

What I have tried:

I tried to get value from 

protected void btnSubmit_Click(object sender, EventArgs e)
        {
string val = ddlCountry.SelectedItem.Value;// here getting empty value
}

推荐答案

.ajax()



请找代码:

.ajax()

please find code:
.aspx apge

<script type="text/javascript">


(document) .ready(function(){
(document).ready(function() {


.ajax({
type: POST
contentType: application / json; charset = utf-8
url: Default.aspx / BindDatatoDropdown
data: {}
dataType: json
success:function(data){
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "Default.aspx/BindDatatoDropdown", data: "{}", dataType: "json", success: function(data) {


这篇关于如何使用ajax绑定项目时获取选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆