用于在DropDownList中分配和显示数据库值的javascript [英] javascript for assigning the and displaying the database value in a DropDownList

查看:60
本文介绍了用于在DropDownList中分配和显示数据库值的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我将数据库列"PermState"的值分配给DropDownList1,以便它应显示为DropDownList1的SelectedIndex,如下所示:

Hi Every one,

I am assigning the value of the database column "PermState" to DropDownList1, so that it should appear as DropDownList1''s SelectedIndex as given below:

DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(dt.Rows[0]["PermState"].ToString().ToUpper()));




在这里,我需要使用javascript来代替C#代码.


请任何人为此提供一个JavaScript.


问候,




Here, I need to use a javascript to do the same instead of C# code.


Please any one give me a javascript for this.


Regards,

推荐答案

在Java脚本下面使用下拉菜单selectedIndex.

在服务器端或客户端传递对象实例(例如comboBox1.clientID),并且必须选择文本女巫.

我认为这段代码将对您有所帮助.


示例:

use below java script for dropdown selectedIndex.

pass the object instance (eg. comboBox1.clientID) either in server side or client side and the text witch u have to select..

I think this code will help you.


Example:

<html>
<head>
<title>Customer Inquiry</title>
<SCRIPT language="JavaScript">
function setIndex(){
    var obj = document.getElementById('select');
    var YourText="MS"; // pass your text from here
    obj.selectedIndex= getIndexOnText(obj,YourText);
}
function getIndexOnText(obj ,YourText)
{
for(i=0; i < obj .length;i=i+1){

    matchText = obj .options[i].text;

    if(YourText == matchText){

        return i;

    }

        }

}

</SCRIPT>
</head>
<body>
    <form name="sysaccess" >
        <select name="select1" id="select">
        <option value="CL">CL</option>
        <option value="EL">EL</option>
   <option value="PS">PS</option>
   <option value="MS">MS</option>
   <option value="GS">GS</option>
        </select>
            <input type="button" onclick="setIndex()()">
    </form>
</body>
</html>


这篇关于用于在DropDownList中分配和显示数据库值的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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