使用asp.net进行下拉列表验证? [英] dropdownlist validation using asp.net?

查看:71
本文介绍了使用asp.net进行下拉列表验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我在这里开发了一个小帖子广告页面,我正在正确编写代码并且发布广告已经成功但是这里的列:id,图片,描述,dateadded ,价格,类别,分类类型,类别名称,州,城市



这些是列名称一旦填写这些列,成功发布,这里没有选择州和城市也成功发布广告即将到来



请回复我如何在这里写逻辑(验证)



请回复我

解决方案

在.cs页面:



IN提交按钮点击事件:

  if (dropdownstate.SelectedItem.Text!=  选择&& dropdowncity.SelectedItem.Text!=  选择
{
// post add
}
else
{
// 警告信息
}
}







在Javascript:

  function  Validate(){
if document .getElementById(' <%= dropdownstate.ClientID%>')。value == 选择){
alert( 请选择状态);
document .getElementById(' <% = dropdownstate.ClientID%>')。focus();
return false ;
}
if document .getElementById(' <%= dropdowncity.ClientID%>')。value == 选择){
alert( 请选择城市);
document .getElementById(' <% = dropdowncity.ClientID%>')。focus();
return false ;
}





按钮:

 <   asp:imagebutton     id   =  btnsubmit    runat   = 服务器    onclientclick   =  return Validate();    xmlns:asp   = #unknown   < span class =code-keyword> /  >  


< blockquote>你可以做出验证像这样的javascript中的离子

下拉默认值0和文本选择城市



  if  document  .getElementById(  ddlCity)。value!=   0
{

// 您的代码
}
else
{
// 选择下拉值验证
}





代码背后你可以做喜欢那个..



 {

if (ddlCity.SelectedValue!= 0
{
< span class =code-comment > // 您的代码
}
其他
{
// 选择下拉值验证
}


}


使用验证组:



< asp:DropDownList runat =serverID =ddl1AutoPostBack =trueOnSelectedIndexChanged =dddl1_SelectedIndexChangedValidationGroup =Valddl/> 





并在提交按钮中对此验证组进行处理:



< asp:Button ID =btn runat =serverText =SubmitOnClick =btn_ClickValidationGroup =Valddl/> 


Dear All,

I developed small post ad page here am writing code properly and post ad has been successfully but here columns:id,Image,description,dateadded,price,categories,categoriestype,categoriesname,state,city

these are column names once fill these columns, post successfully and here without select state and city also post ad successfully is coming

please reply me how i can write logic(validation) here

please reply me

解决方案

In .cs page:

IN submit button click event :

  if (dropdownstate.SelectedItem.Text != "Select" && dropdowncity.SelectedItem.Text != "Select")
                {
//post add
}
else
{
//warning message
}
}



OR
In Javascript:

function Validate() {
      if (document.getElementById('<%= dropdownstate.ClientID%>').value == "Select") {
          alert("Please select the State");
          document.getElementById('<%= dropdownstate.ClientID%>').focus();
          return false;
      }
      if (document.getElementById('<%= dropdowncity.ClientID%>').value == "Select") {
          alert("Please select the City");
          document.getElementById('<%= dropdowncity.ClientID%>').focus();
          return false;
      }



In button:

<asp:imagebutton id="btnsubmit" runat="server" onclientclick="return Validate();" xmlns:asp="#unknown" />


you can make validation in javascript like that
Put dropdown default value 0 and text "Select City"

  if(document.getElementById("ddlCity").value!="0")
  {

          //Your Code
  }
else
  {
        // Select Dropdown Value Validations
   }



At Code Behind You can do like that..

{

  if(ddlCity.SelectedValue != "0")
    {
      //Your Code
     }
else
   {
  // Select Dropdown Value Validations
   }


}


Use validation group :

<asp:DropDownList runat="server" ID="ddl1" AutoPostBack="true" OnSelectedIndexChanged="dddl1_SelectedIndexChanged" ValidationGroup="Valddl" />



And hendle this validation group in your submit button :

<asp:Button ID="btn" runat="server" Text="Submit" OnClick="btn_Click" ValidationGroup="Valddl" />


这篇关于使用asp.net进行下拉列表验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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