tokeyplayer(冰)
  我用的是模板列,因为dropdownlist里的数据也是从数据库里取出的,所以要给dropdownlist装载,我只想到了在编辑dg的时候进行装载,可是老出错,在更新中倒是可以操作,可不符合要求啊,郁闷。
你最后怎么解决的?

解决方案 »

  1.   

    同感痛感ing,这里好像是这样的:
    编辑事件里只能找到显示模板里的控件,
    更新事件里只能找到编辑模板里的控件. 
      

  2.   

    1、template column可以达到你的目的
    2、“System.Web.UI.WebControls.DropDownList dpl=(DropDownList)e.Item.FindControl("ddd");
    Response.Write(((DropDownList)e.Item.FindControl("ddd")).Items[0].Text);
    结果在更新事件就能用,而在编辑事件就会报错:System.NullReferenceException: 未将对象引用设置到对象的实例。”
    确实是这样“编辑事件里只能找到显示模板里的控件,更新事件里只能找到编辑模板里的控件. ”,template column里的声明,声明的只是模版(template),将被aspx解释,解释的时候,分head, footer, item, alternateitem, edit, update等分别装入模版中对应的情况指定的控件
      

  3.   

    选择ItemCreated
    ListItemType elemType=e.Item.ItemType;
    if(elemType==ListItemType.EditItem)
    {
    //在此处添加sql语句。
    //连接数据库,用read();
    sqlDataReader1.Read();
    if (((DropDownList)e.Item.FindControl("DropDownList3")).Items.FindByText(sqlDataReader1.GetString(0).ToString().Trim())!=null)
    ((DropDownList)e.Item.FindControl("DropDownList3")).Items.FindByText(sqlDataReader1.GetString(0).ToString().Trim()).Selected=true;
    }
      

  4.   

    请参考:
    http://www.dotnetjohn.com/articles/articleid21.aspx
      

  5.   

    在Item里是找不到的,要在Cells里找:
    System.Web.UI.WebControls.DropDownList dpl=(DropDownList)e.Item.Cells[0].FindControl("ddd");
    Response.Write(((DropDownList)e.Item.FindControl("ddd")).Items[0].Text);