DropDownList控件的基本用法

 

 

protected   void  Page_Load( object  sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            DateTime dt 
= DateTime.Now;
            DropDownList2.Items.Add(dt.Year.ToString());
            DropDownList3.Items.Add(dt.Month.ToString());
            DropDownList4.Items.Add(dt.Day.ToString());
            DropDownList4.Items.Add(
"23");
        }

       
    }

// 加减乘除
     protected   void  Button1_Click( object  sender, EventArgs e)
    
{
        
int a = int.Parse(TextBox1.Text);
        
int b = int.Parse(TextBox2.Text);
        
int c = 0;

        
switch(DropDownList1.SelectedValue)
        
{
            
case "+":
                c 
= a + b;
                Label2.Text 
= c.ToString();
                
break;
            
case "-":
                c 
= a - b;
                Label2.Text 
= c.ToString();
                
break;
            
case "*":
                c 
= a * b;
                Label2.Text 
= c.ToString();
                
break;
            
case "/":
                c 
= a / b;
                Label2.Text 
= c.ToString();
                
break;
        }

    }

// DropDownList 改变index时发生的事件
     protected   void  DropDownList4_SelectedIndexChanged( object  sender, EventArgs e)
    
{
        Response.Write(DropDownList2.SelectedValue
+"-"+ DropDownList3.SelectedValue+"-"+DropDownList4.SelectedValue);
    }


 

// CheckBoxList 改变index时发生的事件
  protected   void  CheckBoxList1_SelectedIndexChanged( object  sender, EventArgs e)
    
{
        
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
        
{
            
if (CheckBoxList1.Items[i].Selected)   //注意启用postback,这样可以实时观测
            {
                Response.Write(CheckBoxList1.Items[i].Text);
            }

        }

    }


 

 

 

你可能感兴趣的:(c,object,button,textbox,PostBack)