可输入的DropDownList控件

具体代码如下:
<%@ Page language="c#" Codebehind="ddlWriteControl.aspx.cs" AutoEventWireup="false" Inherits="WebDemo.ddlWriteControl" %>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
 
<HTML>
     
<HEAD>
         
<title>ddlWriteControl</title>
         
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
         
<meta name="CODE_LANGUAGE" Content="C#">
         
<meta name="vs_defaultClientScript" content="JavaScript">
         
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        
<style> #div1 {}{ Z-INDEX: 1; LEFT: 250px; WIDTH: 216px; CLIP: rect(3px 280px 21px 110px); POSITION: absolute; TOP: 89px; HEIGHT: 72px } #div2 {}{ LEFT: 250px; WIDTH: 95px; POSITION: absolute; TOP: 89px; HEIGHT: 18px; 2: } </style>
    
</HEAD>
    
<body MS_POSITIONING="GridLayout">
        
<script language="javascript">
        function AddOption()
        
{    
            var val 
= document.getElementById("txtValue").value;
            var option 
= document.getElementById("ddl");
            
            
if(val == "")
            
{
                alert(
"请输入项值");
                
return;
            }

            
if(option.length > 0)
           
{
                
for(var i=0;i<option.length;i++)
                
{
                    
if(option.options[i].value == val)
                    
{
                       alert(
"该值已存在!");
                        
return;
                    }

                }

            }

            
            var option_val 
= new Option(val,val);
                        
            option.add(option_val);
            option.selectedIndex 
= option.options.length-1;
            
        }

        
</script>
        
<form id="Form1" method="post" runat="server">
            
<div id="div1" style="Z-INDEX: 101; WIDTH: 128px; HEIGHT: 72px">                
                
<asp:DropDownList id="ddl" onchange="document.getElementById('txtValue').value = this.value" runat="server"
                    Width
="127">
                    
<asp:ListItem Value="aaa1">aaa1</asp:ListItem>
                    
<asp:ListItem Value="bbb2">bbb2</asp:ListItem>
                    
<asp:ListItem Value="ccc3">ccc3</asp:ListItem>
                
</asp:DropDownList>
            
</div>
            
<FONT face="宋体"></FONT>
            
<div id="div2">                
                
<asp:TextBox id="txtValue" style="PADDING-LEFT:2px;PADDING-TOP:2px" runat="server" Width="127"></asp:TextBox>
                
<input type="button" value="OK" id="btn" onclick="AddOption();">
            
</div>
            
        
</form>
    
</body>
</HTML>
 
posted @ 2010-08-31 19:40  你妹的sb  阅读(679)  评论(0编辑  收藏  举报
百度一下