GridView
   |
   |-----EmptyDataTemplate(空数据的模板)内放一个DetailsView
             |
             |-------DetailsView的一个模板列内的InsertItemTemplate内有放置 一个DropDowmList控件    
                           |
                           |---------DropDowmList如何能在DetailsView的插入新数据时,获取到这个DropDowmList.selectedValue?

解决方案 »

  1.   

    ...Inserting(...
    {
    DetailsView dv = sender as DetailsView;
    DropDownList drp = dv.FindControl("MyDropDownListID") as DropDownList;
    }
      

  2.   

    GridView 中的“行政区划”的模板列中有DropDownList1和Label1 两个控件:
    <EditItemTemplate>
       <asp:DropDownList ID="DropDownList1" runat="server">
       </asp:DropDownList>
    </EditItemTemplate><ItemTemplate>
       <asp:Label ID="Label1" runat="server" Text='<%# Bind("F01030102") >'>
       </asp:Label>
    </ItemTemplate>
    希望达到的效果:
    1.GridView显示的时候,用Label1现实行政区划的中文名称,如“XXX市”;
    2.点击一行的“编辑”按钮时,该行切换到编辑状态,DropDownList1的已选中的Item为Label1中的现实的名称对应的选择.如:DropDownList1.Items.FindByText(“XXX市”).Selected = true;
    问题:
     protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
               
            }
        }
    在这个事件下,如何能查找到该子控件,并获取Label1的值来完成Items的查找?说明,
    DropDownList1的初始化已经完成,不用考虑。
      

  3.   

    if (e.CommandName == "Edit")
            {
              Label Label1 =  e.Item.FindControl("Label1") as Label;
    if(Label1 != null)
    {
    DropDownList1.Items.FindByText(Label1.Text).Selected = true;}
            }
      

  4.   

    楼上的方法不对哦
    编译错误 
    说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS0117: “System.Web.UI.WebControls.GridViewCommandEventArgs”并不包含“Item”的定义
      

  5.   

    if (e.CommandName == "Edit")
            {
              Label Label1 =  e.Row.FindControl("Label1") as Label;
    if(Label1 != null)
    {
    DropDownList1.Items.FindByText(Label1.Text).Selected = true;}
            }
      

  6.   

    老兄,e 里根本就没ROW这选项哦
      

  7.   

    你把这段代码可以放到 RowDataBound 事件中就有了
      

  8.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            string sql = "SELECT * FROM NEM2_T01_03_01 ";
            HybInfo.HybDAO.DynamicEntityService hybDAO = new HybInfo.HybDAO.DynamicEntityService();
    //以上为数据库访问
            Label Label1 = e.Row.FindControl("Label1") as Label;
            DropDownList drp = (DropDownList)e.Row.FindControl("DropDownList1");
            if (drp != null && Label1 != null)
            {
                drp.DataSource = hybDAO.QueryBySQL(sql).DataSource;
                drp.DataTextField = "F01030102";
                drp.DataValueField = "F01030101";
                drp.DataBind();
                drp.Items.FindByText(Label1.Text).Selected = true;        }Label1 还是找不到
      

  9.   

    http://blog.sina.com.cn/s/blog_4a865cff010005u9.html
    参照一下上面这个.