要让DropDownList自动选中指定的项,该如何写代码?谢谢

解决方案 »

  1.   

    ListItem item = new ListItem(ds.Tables[0].Rows[0][1].ToString(),ds.Tables[0].Rows[0][0].ToString());
    int index = ((DropDownList)datagrid.Items[j].Cells[num].Controls[1]).Items.IndexOf(item);
    if(index > -1)

    ((DropDownList)datagrid.Items[j].Cells[num].Controls[1]).Items[index].Selected = true;
    }
      

  2.   

    protected System.Web.UI.WebControls.DropDownList selType;
    selType.SelectedValue=你想显示选项的Value值;
      

  3.   

    protected System.Web.UI.WebControls.CheckBox CheckBox1;
    CheckBox1.Checked=true;
      

  4.   

    再问一个,
    DropDownList中总共有几项,是哪个属性呢?谢谢
      

  5.   

    DropDownList1.Items.Count;
    基础知识要巩固呀:)
      

  6.   

    ddl.SelectedValue="aa";
    chk.Checked=true;int a=DropDownList1.Items.Count;
      

  7.   

    你把 SelectedValue   和 SelectedText 这两个好好看看``
      

  8.   

    SelectedValue="aa";//该值一定要存在,不然会出错。
    SelectedText="aa";//值可以不存在。
    安全的就用2楼的,做个判断.