gridview的编辑模式(EditItemTemplate)里,某列嵌套一个dropdownlist
因为修改是限制,所以我就只能用dropdownlist,ddl里的值是从另外一个表里抓的。具体来说 当用户看的时候,这列的值是:北京  但是要修改的话,我就要从CITY表里获得数据 比如限制修改成  上海或重庆或北京(默认还是北京),不能成为其他的字段 我现在都不知道该在哪个事件里写了,请高手赐教

解决方案 »

  1.   

    #region 对数据行的设置
            if (gvr.RowType == DataControlRowType.DataRow)
            {
               
            }
            #endregion
      

  2.   

    RowDataBind事件里绑定数据通过findcontrol找到DLL,填充数据
      

  3.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DropDownList DDL = (DropDownList)e.Row.FindControl("DropDownList1");
                DataRowView DRV = (DataRowView)e.Row.DataItem;
                int id = Convert.ToInt32(DRV["stid"]);
                DDL.SelectedIndex = id;
                DDL.DataSource = ConStr.Dt("select * from bigtitle");
                DDL.DataBind();
                DDL.DataTextField = "btid";
                DDL.DataValueField = "btname";
            }
        }
    我这么写,点编辑的时候显示找不到dropdownlist1 谁写过,把具体代码给我把
      

  4.   

    直接在你的 EditItemTemplate里面的 DropDownList 对象里面注册事件就可以了现在支持这个
      

  5.   

    不知道楼主是不是这个意思,给你参考一下
    后台代码:  
    public SqlDataReader ddlBind()
        {
            SqlDataReader dr = Pro.selectAllBrand();//从数据表取出数据
            return dr;
        }
    前台页面绑定(DataSource='<%#ddlBind()%>'):
     <asp:TemplateField HeaderText="品牌">
          <EditItemTemplate>
             <asp:DropDownList ID="DropDownList4" runat="server" DataSource='<%#ddlBind()%>' DataTextField='brand' DataValueField='id' Width="70px">
                                                                <asp:ListItem Value="00">-请选择-</asp:ListItem>
                                                            </asp:DropDownList>
                                                           
                                                        </EditItemTemplate>