关于下拉列表文本 [英] About Dropdownlist text

查看:120
本文介绍了关于下拉列表文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢在页面中使用dropdownlist并为它设置必填字段。所以当我获取文本并绑定到dropdownlist时,值会显示在选择位置,所以如果我点击按钮就会触发验证...

解决方案

试试这个:



ClientSide

Javascript:

< script language =   javascript  type =   text / javascript> 
function validate(){
if 文档 .getElementById(<跨度类= 代码串> ' <跨度类= 代码串><%= DropDownList1.ClientID%GT;')。value == 选择){
alert( 请选择!);
document .getElementById(' <% = DropDownList1.ClientID%>')。focus();
return false ;
}
}

< / script>





加价:

 <   asp:按钮    id   =  Button1    runat   =  server    text   = 按钮    onclick   =  Button1_Click    onclientclick   =  ret urn validate()  /  >  







ServerSide

在.CS页面:

  //   Bind Dropdown  
DropDownList1 .Items.Insert( 00 选择);
DropDownList1.SelectedIndex = 0 ;







点击按钮事件:

  if (ddl_DropDownList1.SelectedItem.Text!=  选择
{

}
else
{
// 提示
}


Hi Iam using dropdownlist in page and setting required field for it..so when I am getting text and binding to dropdownlist the value is showing at select place so if I click on button it is firing validation...

解决方案

Try this:

ClientSide:
Javascript:

<script language="javascript" type="text/javascript" >
     function validate() {
         if (document.getElementById('<%=DropDownList1.ClientID %>').value == "Select") {
             alert("Please Select!");
             document.getElementById('<%=DropDownList1.ClientID %>').focus();
             return false;
         }
     }
       
    </script>



Markup:

<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" onclientclick="return validate()"/>




ServerSide:
In .CS page:

//Bind Dropdown
           DropDownList1.Items.Insert(00, "Select");
           DropDownList1.SelectedIndex = 0;




In button click event:

if (ddl_DropDownList1.SelectedItem.Text != "Select")
{

}
  else
{
  //alert
}


这篇关于关于下拉列表文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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