如何编写函数并验证多个下拉列表 [英] how to write the function and validate mutiple dropdownlist

查看:44
本文介绍了如何编写函数并验证多个下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下



学生ID下拉列表1



课程下拉列表2



课程时间下拉列表3





i想要验证是否未选择上述3个下拉列表中的任何一个想要显示消息请选择





为什么我可以使用c#在asp.net中验证drodpownlist。





问候,

Narasiman P.

My code as follows

Student ID Dropdownlist1

Course Dropdownlist2

Course timings Dropdownlist3


i want to validate if any of the above 3 Dropdownlist is not selected want to show the message "Please select"


for that how can i validate drodpownlist in asp.net using c#.


Regards,
Narasiman P.

推荐答案

Hi Narasiman,



要验证下拉列表选择属性,您可以使用此功能

Hi Narasiman,

To validate the dropdownlist selection property you can use this function
protected void ValidateDDL(DropDownList ddl)
        {
            if (ddl.SelectedIndex == -1) //Customize index value 
            {
                //Throw your error here
            }
        }
Function Call:

ValidateDDL(Dropdownlist1);
ValidateDDL(Dropdownlist2);
ValidateDDL(Dropdownlist3);



同样也可以使用Javascript验证,这取决于你...


Same can also validate using Javascript, it depends on you...

function validate()
{
   if(document.getElementById("ddlList").value == "")
   {
      alert("Please select value"); // prompt user
      document.getElementById("ddlList").focus(); //set focus back to control
      return false;
   }
}



希望这会对你有所帮助。



问候,

RK


Hope this helps you a bit.

Regards,
RK


看看这个..

这对你有帮助。

Link 1 [ ^ ]

链接2 [ ^ ]
Check out this..
This will help you.
Link 1 [^]
Link 2 [^]


这篇关于如何编写函数并验证多个下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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