如果条件在下拉列表中选择索引更改事件,该如何使用 [英] how to use if condition in dropdown selected index change event

查看:92
本文介绍了如果条件在下拉列表中选择索引更改事件,该如何使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单中使用了两个dropdownlist.我在dropdownlist1中给出If条件,以更改dropdownlist2的值,但它不起作用...这是我的代码


I am using two dropdownlist in my form in. i give If condition in dropdownlist1 for changing the dropdownlist2 values but it is not working ...this is my code


if (DropDownList1.Text == "A")
{
    DropDownList2.Items.Add("1");
    DropDownList2.Items.Add("2");
}
if (DropDownList1.Text == "B")
{
    DropDownList2.Items.Add("3");
    DropDownList2.Items.Add("4");
}



任何人都告诉如何编写此代码的代码



Any one tell how to write the code for this one

推荐答案

尝试使用DropdownList1.SelectedIndexChanged()中的if条件并设置AutoPostBack = true
try using if condition in DropdownList1.SelectedIndexChanged() and set AutoPostBack=true
if(dropdownlist1.SelectedValue=="A")
{
}


代替

if(dropdownlist1.Text)


您设置了 dropdown1的属性是否为<code> true


DropDownList1AutoPostBack属性设置为True.

还可以通过如下更改代码来进行检查.
Set AutoPostBack property of DropDownList1 to True.

Also check by changing your code as below.
if (DropDownList1.SelectedItem.Text.Equals("A"))
{
  DropDownList2.Items.Add("1");
  DropDownList2.Items.Add("2");
}

if (DropDownList1.SelectedItem.Text.Equals("B"))
{
  DropDownList2.Items.Add("3");
  DropDownList2.Items.Add("4");
}


这篇关于如果条件在下拉列表中选择索引更改事件,该如何使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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