本帖最后由 fangquan1980 于 2010-02-02 13:11:56 编辑

解决方案 »

  1.   

    直接设置dropdownlist的数据=dataset        this.dropdownlist.DataSource = ds;
            this.dropdownlist.DataTextField = "text";
            this.dropdownlist.DataValueField = "id";
            this.dropdownlist.DataBind();
      
      楼主。。您贴那么多代码出来  不累吗?
      

  2.   


    不是这样的,之所以贴这么多代码,就是我觉得这是特殊的。实际上dropdownlist在后台是无法直接读出的,建议你再仔细看看我的代码。
      

  3.   

              <asp:DropDownList ID="商品分类" runat="server" DataSourceID="SqlDataSource2" SelectedValue='<%# Bind("商品类别编号") %>' DataTextField="商品类别名称" DataValueField="商品类别编号">你没设置ID  当然获取不到。
      

  4.   

    你可以试一下,这个控件是在EditItemTemplate里
      

  5.   

    DropDownList 商品分类 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("商品分类");
      

  6.   

    用这样的方式取出你的控件protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    if (e.Row.RowState == DataControlRowState.Edit || ((int)e.Row.RowState) == 5)
                    {
                        TextBox txtIndicator = (TextBox)(e.Row.FindControl("txtIndicator"));
                        if (txtIndicator != null)
                        {
                            txtIndicator.Text = this.myGridView.DataKeys[e.Row.RowIndex].Values["Indicator"].ToString();
                        }                }
    }
      

  7.   


    我想用我弄好的dataset 去做DropDownList的数据源,就是后台想把注释的去除;前台DropDownList不用SqlDataSource2做数据源。但总是没数据啊DropDownList 商品分类 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("商品分类");/*
                商品类别 商品类别1 = new 商品类别();
                商品类别1.数据库连接字符串 = ConfigurationManager.ConnectionStrings["汇通玩具网站ConnectionString"].ToString();
                商品类别1.列出第一级商品类别存储过程名 = "列出第一级商品类别存储过程";
                商品类别1.列出该级下的商品类别存储过程名 = "列出该级下的商品类别存储过程";
                商品分类.DataSource = 商品类别1.列出所有商品类别();
                //商品分类.DataTextField = "商品类别名称";
                //商品分类.DataValueField = "商品类别编号";
                商品分类.DataBind();
                商品类别1.清空输出表();
    */
      

  8.   

    楼主居然用中文作字段名,niubility
      

  9.   


    也就是说要用你的ds填充dropdownlist而不用SqlDataSource2来填充是吧那你要把DataSourceID="SqlDataSource2"这句去掉
    还要看看GridView1.Rows[e.RowIndex].FindControl("商品分类")这句能找到这个控件吗
      

  10.   


    why?我觉得代码不是很多啊
      

  11.   

    using 商城;namespace 汇通玩具网站.admin
    楼主真勇敢,估计我在程序里用一个汉字变量 项目经理会骂我SB,而且会怀疑我的技术....
      

  12.   


    我觉得初学者用中文比较容易看清问题,而且目前看来未有何不妥,虽然很多人鄙视我,但是却没有一个说出道理。如果真的不可以,为何.net又支持中文变量呢?我觉得习惯问题是主要原因。