在DataGrid1_ItemDataBound中重新绑定DropDownList ,并将e.item.cell[]的值显示给DropDownList ,可以通过 DropDownList 的findbyValue 找到和contact对应的记录更新时,先用 Update 语句修改数据库中的值

解决方案 »

  1.   

    先将Phone表的Type 和Name绑定到 DropDownList , 再去设定要显示的值不知我说的清楚不清楚?
      

  2.   

    DataSet Ds = Conn.sqlDs("select * from phone");
    DropDownList1.DataSouce = Ds;
    DropDownList1.DataTextField = "phonename";
    DropDownList1.DataValueField = "phonetyp";
    DropDownList1.DataBoud();DropDownList1.FindByValue(e.Item.Cell[DataGrid中的列的序号].selected = true;
      

  3.   

    我怎么这么笨,仔细看了两三遍还是没理解楼主的意思?为什么要把一个表的数据绑室到两个DropDownList上呢?
      

  4.   

    在DataGrid的ItemDataBound事件处理程序中绑定,象这样:void DataGrid1_ItemDataBound(object src,DataGridItemEventArgs e){
    if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem){
    DropDownList list=(DropDownList)e.Item.FindControl("DropDownList1");
    if(list!=null){
    //在这里绑定数据
    list.DataSource=//你从phone表中取出的数据
    list.DataBind();
    //获取DataGrid当前行绑定的phonetype值
    int phonetype=(int)((DataRowView)e.Item.DataItem)["phonetype"];
    //根据上面的phonetype值从phone表中选出对应的phonename值,赋给phonename变量
    ....
    ListItem litem=list.Items.FindByText(phonename);
    if(litem!=null)
    litem.Selected=true;
    }
    }
    //再绑定FooterTemplate中的DropDownList2
    else if(e.Item.ItemType==ListItemType.Footer){
    DropDownList list=(DropDownList)e.Item.FindControl("DropDownList2");
    if(list!=null){
    //从phone表中获取数据绑定到DropDownList2上
    list.DataSource=...//取出的数据
    list.DataBind();
    }
    }
    }