使用下拉选择文本框是可见的 [英] Using dropdown selection textbox is visible

查看:87
本文介绍了使用下拉选择文本框是可见的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在跑步模式下如下





Coursname dropdownlist1

AFF

PST

请加入新课程



textbox1



当我点击请在dropdownlist1中添加到新课程将显示textbox1。





我的代码如下



protected void dropdownlist1_SelectedIndexChanged1(object sender,EventArgs e)

{

if(dropdownlist1.SelectedItem.Text ==请加入新课程)

{

textbox1.Visible = true;

}



}



当我点击时请在下拉列表中添加新课程另外的文字请添加到新课程中添加。



在运行模式下如下



Coursname dropdownlist1

请加入新课程

请加入新课程



当我点击请再次添加到dropdownlist1的新课程时请在dropdownlist1中添加新课程。



上面的代码有什么问题

In run mode as follows


Coursname dropdownlist1
AFF
PST
Please add to new course

textbox1

When i click the please add to new course in dropdownlist1 textbox1 will be visible.


My code as follows

protected void dropdownlist1_SelectedIndexChanged1(object sender, EventArgs e)
{
if (dropdownlist1.SelectedItem.Text == "Please add to new course")
{
textbox1.Visible = true;
}

}

when i click the please add to new course in dropdownlist another text please add to new course is added.

In run mode as follows

Coursname dropdownlist1
please add to new course
please add to new course

when i click the please add to new course in dropdownlist1 again please add to new course is added in the dropdownlist1.

what is the problem in my above code

推荐答案

请试试这个示例代码:



Please try this sample code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;



namespace WindowsFormsApplication1
{
   
    
    public partial class Form1 : Form
    {
        BindingList<string> course = new BindingList<string>() { "AFF", "PST", "Please add to new course" };
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DropDownList1.DataSource = course;
            DropDownList1.DisplayMember = "course";
            DropDownList1.ValueMember = "course";
            textBox1.Visible = false;
            textBox1.Text = "Please add to new course";
        }

        private void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedItem.ToString() == "Please add to new course")
            {
                textBox1.Visible = true;
            }
            else
            {
                textBox1.Visible = false;
            }
        }

        private void textBox1_Leave(object sender, EventArgs e)
        {
           
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && !course.Contains(textBox1.Text) && !string.IsNullOrEmpty(textBox1.Text))
            {
                course.Add(textBox1.Text);
                DropDownList1.SelectedItem = textBox1.Text;
            }
        } 

    }
}


can you add autopostback=trun in your source page


这篇关于使用下拉选择文本框是可见的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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