客户端选项添加到ASP.NET DropDownList控件和ViewState的Prorblem [英] Client Side option append to asp.net DropDownList Control and ViewState Prorblem

查看:123
本文介绍了客户端选项添加到ASP.NET DropDownList控件和ViewState的Prorblem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法附加选项,一个asp.net DropDownList控件和视图状态在同一时间吗?

Is there any way of appending options to an asp.net dropdownlist control and viewstate at the same time?

我的DropDownList是空的,当页面加载那么我附加来自客户端的code选项。

My dropdownlist is empty when the page is loaded then I am appending options from client-side code.

我已经实现级联DropDownList的功能,我使用的JQuery了点。

I have implemented cascading dropdownlist function and I used JQuery for that.

目前的拳头,我AjaxControlToolkit中使用的控制CascadingDropdown,它可以这样做,但不知道怎么办。任何想法?

At fist I was using AjaxControlToolkit CascadingDropdown control and it can do that but don't know how. any idea?

推荐答案

追加选项,下拉列表控件将不能在code反映的身后,因为你不能在下降的视图状态换下来列表中,我也有同样的问题,同时从下拉列表到另一个,而且为我工作的解决方案,移动方案的工作是创建另一个JavaScript函数,循环的下拉列表,并采取了价值,我想和它们附加一个隐藏字段,以便我可以做我的队伍在code后面。 在提交按钮调用这个javascript函数,你会发现下拉列表值作为一个逗号隐藏字段分开。

Appending options to a drop down list control will not reflect on the code behind, because you can't change in the view state of the drop down list, I have had the same problem while working with moving options from a drop down list to another and the solution that worked for me is to create another javascript function that loops on the drop down list and takes that values that i want and append them to a hidden field so that i can do my procession on the code behind. In the submit button call this javascript function and you will find the drop down list values as a comma separated in the hidden field.

function SaveList()
{
//Clear the hidden field
var hField =  document.getElementById('<%= YourHiddenField.ClientID %>'); 
hField.value = '' ;

var selectedList = document.getElementById('<%= YourDropDownList.ClientID %>')
for(i = 0; i < selectedList.options.length; ++i)
{         
hField.value = hField.value + ',' + selectedList.options[i].value;
}

这篇关于客户端选项添加到ASP.NET DropDownList控件和ViewState的Prorblem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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