ListMonth.SelectItems[ListMonth.SelectIndex].Value

解决方案 »

  1.   

    ListMonth.SelectedIndex.value=clock.CurrentTime.Month;(初始的值)
      

  2.   

    ListMonth.Items.FindByText(DateTime.Now.Month.ToString()).Selected=true;
      

  3.   

    在DropDownList的selcetedindex_changed事件中写入你想要的代码
      

  4.   

    再dropdownlist的SelectedIndexChanged事件里添加:
    int month=int.Parse(ListMonth.SelectedItem.Text);
    SqlCommand cmd=new SqlCommand("updMonth",cn);
    cmd.CommandType=CommandType.StoredProcedure;
    cn.Open();
    SqlParameter param=cmd.Parameters.Add("@Month");
    param["@Month"].Value=month;
    param=cmd.Parameters.Add("@ID");
    param["@ID"].Value=intID;//数据库相应字段ID
    cmd.ExecuteNonQuery();
    cn.Close();
    存储过程写法:
    Create Procedure updMonth
    (@ID int,
     @Month int)
    as
    Update table Set Month=@Month where ID=@ID
      

  5.   

    DropDownList的属性enableviewstate设置成true
      

  6.   

    还有我有很多的DropDownListBox
    年月日时分 五个
      

  7.   

    你的DropDwonList是数据库绑定还是直接在控件里设置的?ListMonth.SelectedIndex=clock.CurrentTime.Month;SelectIndex应该是0,1,2,.....,没有选中的是-1
      

  8.   

    DropDownList控件有一个AutoPostBack属性,你将它设成True就可以执行它的SelectedIndexChanged事件了,不设这个属性是不行的。
      

  9.   

    谢谢上面的回答我的意思是把年月日时分五个都做成dropdownlist
    首先是显示出数据库中一个datetime
    然后再把更改后的转化为datetime后更新到数据库
    如果每个DropDownList都这么用SelectedIndexChanged很麻烦阿