当我在客户端创建选项时,如何在服务器端获取下拉选择值 [英] how to get dropdown selecteditem value in server side when i created option in client side

查看:47
本文介绍了当我在客户端创建选项时,如何在服务器端获取下拉选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的javascript代码

my javascript code

$().ready(function () {
       $.ajax({
           type: "POST",
           url: "../WebService.asmx/GetDistricts",
           data: "{}",
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           success: function (msg) {
               BindDist(msg.d);
           }
       });
   });

as

function BindDist(msg) {
       $.each(msg, function () {

           $("#dropDist").append($("<option></option>").val(this['DistrictId']).html(this['Name']));

       });
   }

在服务器端我希望通过dropDist.selectedItem获取价值。但我可以获得价值怎么做。

in server side i want to get value by dropDist.selectedItem.but i can't get value how to do it.

int DistrictId = Int32.Parse((dropDist.SelectedValue).ToString());

我如何获得服务器端的下拉选择值?任何帮助我都非常感激。

how i get the dropdown selected value in server side?any help me is highly appreciated.

推荐答案

如果在javascript中添加选项,则无法从下拉列表中获取选定的值。此外,您也丢失了SelectedIndexChanged事件处理程序。如果您需要在客户端填充下拉列表并且仍然能够使用SelectedValue属性和SelectedIndexChanged事件,则需要开发自己的ajax服务器控件。或者您可以使用AjaxControlToolkit库中的ComboBox。

You can't get selected value from dropdown if you adding options in javascript. Also, you lost SelectedIndexChanged event handler as well. If you need to fill dropdown on client and still have ability to use SelectedValue property and SelectedIndexChanged event you need to develop own ajax server control. Or you can use some like ComboBox from AjaxControlToolkit library.

尽管如此,如果您仍然希望在客户端上使用常规的DropDown,那么您可以在服务器上获得选定的值在那里: string dropDistSelectedValue = Request.Form [dropDist.UniqueID];

Despite of all above, if you still want to use regular DropDown filled on client then you can get selected value on server as there: string dropDistSelectedValue = Request.Form[dropDist.UniqueID];

这篇关于当我在客户端创建选项时,如何在服务器端获取下拉选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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