Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Comments
Wendelius 14-Aug-15 6:33am    
The code you've posted does not add rows to the drop down list. Please check what happens for example in TextBox1 or other places (other event handlers etc)
DamithSL 14-Aug-15 6:33am    
where you adding items to dropdownlist1?
ZurdoDev 14-Aug-15 7:24am    
What?
Arasappan 14-Aug-15 7:28am    
put update panel .. on your dropdownlist and textbox

Please try this sample code :

C#
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;
            }
        } 

    }
}
 
Share this answer
 
v2
C#
can you add autopostback=trun in your source page
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900