在DataGrid中显示如下:编号        专业名称           上级专业编号     编辑
  1           IT                    0           编辑
  2           网络                  1           编辑
  3           数据库                1           编辑有一个DropDownList控件,里面显示的是上级专业编号为0的专业
value=编号,text=专业名称现在我想点击一下DataGrid一行中的“编辑”按钮,然后在DropDownList中选定value=上级专业编号的选项 

解决方案 »

  1.   

    在DataGrid的ItemDataBound事件里设置DropDownList的SelectedItem
      

  2.   

    在datagrid的html中设置onItemCommand="selectData"在代码文件中,定义
    public  sub  selectData(send as object, e as datagridCommandEventArgs)
               if  lcase(e.commandName)="上级专业编号 " then
                  ....
               end if
    end sub
      

  3.   

    datagrid_ItemDataBound事件中:if(e.Item.ItemType == ListItemType.EditItem)
    {
    DropDownList dlname = (DropDownList)e.Item.FindControl("dlname"); if(dlname!=null)
    {
    try
    {
    dlname.SelectedValue = 绑定值;
    }
    catch(Exception)
    {
    dlname.SelectedIndex = 0;
    }
    }
    }
      

  4.   

    强烈BS    snowpine999([彼岸烟花][一定要up出个★])呵呵,只需要在事件里DropDownList赋值,就可以了,像啤酒肚那样,应该就可以.
      

  5.   

    不行啊,我还是不明白啊
    我是这样写的
    private void specialityDataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    txtOper.Text="update"; //设置状态值为修改
    //获取被操作的那一行
    TableRow tr=e.Item;
    //获取每个TableCell的数据
    txtspecialityTypeID.Text=tr.Cells[0].Text;
    txtspecialityTypeName.Text=tr.Cells[1].Text;
                                DropDownList.SelectedValue=tr.Cells[2].Text;
    }
    但是提示
    “System.Web.UI.WebControls.DropDownList”并不包含对“SelectedValue”的定义
      

  6.   

    private void specialityDataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    txtOper.Text="update"; //设置状态值为修改
    //获取被操作的那一行
    TableRow tr=e.Item;
    //获取每个TableCell的数据
    txtspecialityTypeID.Text=tr.Cells[0].Text;
    txtspecialityTypeName.Text=tr.Cells[1].Text;
                                //选定
                                DropDownList.Items.FindByValue(tr.Cells[2].Text).Selected = true;
    }
      

  7.   

    查一句 dropdownlist在选定前先释放原先选则 DropDownList.Items.Selected = false;
    如下:
    private void specialityDataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    txtOper.Text="update"; //设置状态值为修改
    //获取被操作的那一行
    TableRow tr=e.Item;
    //获取每个TableCell的数据
    txtspecialityTypeID.Text=tr.Cells[0].Text;
    txtspecialityTypeName.Text=tr.Cells[1].Text;
                                //选定
                                DropDownList.Items.Selected = false;
                                DropDownList.Items.FindByValue(tr.Cells[2].Text).Selected = true;
    }