比如显示时为: 
姓名         部门 
张三     销售一部 
李四     销售二部 进入编辑时,要求部门用DropDownList进行选择并且进入编辑模式时使当前部门项被选中
   最好能有详细的代码,谢谢了~在线等待~~

解决方案 »

  1.   

    不用代码实现把那列转换为模板列
    再编辑模板列
    在模板列的ItemTemplate里添加一个dropdownlist 进行双重绑定(绑定一个数据源,再editdatabing绑定部门ID)
    这样就可以了
      

  2.   

    CS.文件 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if(e.Row.RowType== DataControlRowType.DataRow)
            {
                DropDownList DropDownList1 = (DropDownList)e.Row.FindControl("DropDownList1");            DropDownList1.DataSource = GetTableForDropdownList();
                DropDownList1.DataTextField = "Name";
                DropDownList1.DataValueField = "PartMent";
                DropDownList1.DataBind();
            }
        }    private DataTable GetTableForDropdownList()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("PartMent", typeof(string));        DataRow row = dt.NewRow();
            row["Name"] = "张三";
            row["PartMent"] = "销售一部";
            dt.Rows.Add(row);        DataRow row1 = dt.NewRow();
            row1["Name"] = "李四";
            row1["PartMent"] = "销售二部";
            dt.Rows.Add(row1);        return dt;
        }html:<body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
                <Columns>
                    <asp:TemplateField HeaderText="AAAAA">
                        <ItemTemplate>
                            <asp:DropDownList ID="DropDownList1" runat="server">
                            </asp:DropDownList>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
        </form>
    </body>
      

  3.   

    双击之后有个changed事件,在里面写代码,获得当前的项的索引,然后在编辑状态得到这个索引就可以了,不是很难的,摸索一下就可以做出来
      

  4.   

    搞了一天了,麻烦哪位老师给点具体的例子呀~~
    还有就是我在RowDataBound事件中,怎么也获取不到当前需要绑定DROPDOWNLIST的值
    string wcm_level = this.GridView_Manager.DataKeys[e.Row.RowIndex]["wcm_level"].ToString();
      要报错..
      

  5.   

    foreach (GridViewRow gr in this.GridView1.Rows)
                {
                    string id = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
                }得有循环,那么多行呢,它不知道是哪行
      

  6.   

    不好意思,忘改了个地方 foreach (GridViewRow gr in this.GridView1.Rows)
                {
                    string id = GridView1.DataKeys[gr.RowIndex].Value.ToString();
                }
      

  7.   

    7楼的
    在加个附值的语句就可以了protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if(e.Row.RowType== DataControlRowType.DataRow)
            {
                DropDownList DropDownList1 = (DropDownList)e.Row.FindControl("DropDownList1");            DropDownList1.DataSource = GetTableForDropdownList();
                DropDownList1.DataTextField = "Name";
                DropDownList1.DataValueField = "PartMent";
                DropDownList1.DataBind();//取得XXX 部门资料
    DropDownList1.SelectValue = "XXXX";
            }
        }
      

  8.   

    楼上正解。不过最好添加一个判断,如果没找到XXXX,会抛出异常的。if(DropDownList1.Items.FindByValue("XXXX") != null)
        DropDownList1.SelectValue   =   "XXXX";