使用javascript从gridview的下拉列表中检索选定的值. [英] retrieving a selected value from a dropdown list in a gridview using javascript.

查看:60
本文介绍了使用javascript从gridview的下拉列表中检索选定的值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用JavaScript检索gridview内部控件的值时遇到麻烦.下面是一个示例.

I''m having trouble retrieving values for controls inside a gridview using javascript. An example below.

function percentIT() {
        var DropDown = document.getElementById('DropDownList2');
        alert(DropDown);
    }



DropDownList2显然是控件的名称,我已经检查了它.

我已经看过类似以下的代码,但是它似乎对我不起作用.



DropDownList2 is obviously the name of the control and I have checked this.

I''ve seen code like the following but it does not seem to work with me.

function percentIT() {
        var DropDown = document.getElementById('DropDownList2').value;
        alert(DropDown);
    }



我是客户端代码的新手,需要一些帮助

谢谢



I''m new to client side code and need some help

Thanks

推荐答案

尝试使用GridView1_RowDataBound事件.
事件触发后,对于每一行(作为事件参数传递),找到下拉列表.
诸如e.Row.FindControl("DropDownList1");
Try using the GridView1_RowDataBound event.
Once the event fires, for each row (passed as event parameter), locate the dropdown.
Something like e.Row.FindControl("DropDownList1");


之类的东西,ASP.NET将通过为控件所在的容器添加前缀来管理ID.DropDownList2可能是您已分配的内容,但是在呈现时它将是类似的
ASP.NET will manage IDs by adding prefixes for the container the control is in. DropDownList2 may be what you have assigned but when rendered it will be something like


ctrl00_DropDownList2.查看页面的渲染源,您将看到此内容.

使用JQuery可以做到这一点,无论前缀是什么,都可以找到控件.
ctrl00_DropDownList2. View the rendered source of your page and you will see this.

Using JQuery you would do this, which will find the control no matter what the prefix is.


这篇关于使用javascript从gridview的下拉列表中检索选定的值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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