这是原帖:原帖首先谢谢大家的热情! 但是 我很无奈
难道我描述问题不够清楚吗?   我现在想实现的效果是  当我点击编辑之后  类型那一列呈现的不是textbox  而是一个下拉菜单  例如DropDownList 对于GV的列<asp:BoundField HeaderText="类型" />正常情况是这样的: 当其处于非编辑状态时 它的呈现样式是一个table的cell样式   当处于编辑状态时,它的呈现样式是cell里面放一个TextBox  这样就可以编辑里面的内容 我要的样式是  当处于编辑状态时,它的呈现样式是cell里面放一个Dropdownlist   当非编辑状态时  它的呈现样式就是普通的BoundField   回答者告诉我的答案几乎全是非编辑状态 呈现出Dropdownlist  这个根本不难  而且MSDN也有示例  但我不是要的这种请大家看清楚描述再帮我解答  谢谢 

解决方案 »

  1.   

    1.先把DropDownList所在的列转换成TemplateField(模板列)
    2.在GridView里添加三个事件OnRowEditing,OnRowCancelingEdit,OnRowUpdating
       再在事件上写上相应的代码代码片段:
    ASPX文件:
    <asp:GridView ID="gvRequestRoleList" runat="server" AutoGenerateColumns="False" CellPadding="4"
             ForeColor="#333333" GridLines="None" AllowPaging="True" OnPageIndexChanging="gvRequestRoleList_PageIndexChanging"
             OnRowEditing="gvRequestRoleList_RowEditing" OnRowCancelingEdit="gvRequestRoleList_RowCancelingEdit"
             OnRowUpdating="gvRequestRoleList_RowUpdating">
    .......
    <asp:TemplateField HeaderText="申请权限">
                   <EditItemTemplate>
                      <asp:DropDownList ID="ddlRequestRole" runat="server">
                         <asp:ListItem Value="Common">普通用户</asp:ListItem>
                         <asp:ListItem Value="Intermediate">中级用户</asp:ListItem>
                         <asp:ListItem Value="Senior">高级用户</asp:ListItem>
                         <asp:ListItem Value="Admin">超级用户</asp:ListItem>
                      </asp:DropDownList>
                   </EditItemTemplate>
                   <ItemTemplate>
                      <asp:Label ID="Label1" runat="server" Text='<%# Bind("RequestRoleCHName") %>'></asp:Label>
                   </ItemTemplate>
                </asp:TemplateField>
    .......
    </asp:GridView>CS文件:
    //用户按"修改权限"(更新)时
     protected void gvRequestRoleList_RowEditing(object sender, GridViewEditEventArgs e)
          {
             gvRequestRoleList.EditIndex = e.NewEditIndex;         
              //绑定数据
             RequestRoleListDataBind();
          }//用户取消操作时
          protected void gvRequestRoleList_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
          {
             gvRequestRoleList.EditIndex = -1;
              //绑定数据
             RequestRoleListDataBind();
          }//更新操作
          protected void gvRequestRoleList_RowUpdating(object sender, GridViewUpdateEventArgs e)
          {
    //获得DropDownList 控件
             DropDownList ddlRequestRole = gvRequestRoleList.Rows[e.RowIndex].Cells[5].FindControl("ddlRequestRole") as DropDownList;
             string roleName = ddlRequestRole.SelectedItem.Value;
             Label lblUserName = gvRequestRoleList.Rows[e.RowIndex].Cells[2].FindControl("lblUserName") as Label;
             string userName = lblUserName.Text;          //更新用户的角色
             ChangeRole(userName, roleName);          
            
              //审核用户的申请
             //....(略)         //刷新页面
              //....(略)      }
      

  2.   

    BoundField的是默认模板其中包括了编辑状态和一般状态,你只能是用BoundField,或者自定义模板,非编辑状态下 其实就个Label
    这个就是你要想要的想过嘛
                     <asp:TemplateField>
                        <EditItemTemplate>
                            <asp:DropDownList ID="DropDownList1" runat="server">
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
      

  3.   

    还有发现你居然连绑定都不会.........这个要绑定就直接....
    <asp:Label ID="Label1" runat="server" Text='<%# Eval("绑定的字段")%>'> </asp:Label> 编辑模板下的那个dropdownList  可以两种办法绑定第1是选中gridview点编辑模板,然后选中编辑模板,你会看到你的dropdownlist,然后拖入sqldatasource进行绑定或者在gridView进入编辑状态下的时候,动态在事件下用 findControl找到dropdownlist进行手动绑定
      

  4.   


    //参考:
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" Width="590px" >
                    <Columns>
                        
                        <asp:TemplateField HeaderText="类别">
                            <ItemTemplate>
                                <%# Eval("类别字段") %>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:Label runat="server" id="sp" Text='<%#Eval("类别字段") %>' Visible=false/>
                                <asp:DropDownList ID="ddlInfo" runat="server">
                                </asp:DropDownList>
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="True" />
                    </Columns>
                </asp:GridView>//后台事件:
     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //如果为编辑情况下时,绑定下拉框控件。
            DropDownList ddlinfo = (DropDownList)e.Row.FindControl("ddlInfo");
            if (ddlinfo != null)
            {
                ddlinfo.DataSource = bsi.SelectAll(); //指定下拉框数据源
                ddlinfo.DataTextField = "类别名";
                ddlinfo.DataValueField = "类别id";
                ddlinfo.DataBind();
                //选定为默认值
                ddlinfo.SelectedValue = ((Label)e.Row.FindControl("sp")).Text;
            }
        }
      

  5.   

    也可以看看这儿
    http://www.componentart.com/webui/demos/demos_control-specific/grid/editing/editing_dataCallbackMode/WebForm1.aspx
      

  6.   

    建议楼主,还是抽一点点时间看看Insus.NET帖出来链接中的视频.