在 DataBind 的事件里面再绑定 DataGrid 的数据.

解决方案 »

  1.   

    NekChan(骑蜗牛看星星)
    能举个实力吗?
    我才接触.net3个月,谢谢你啊`````````````
      

  2.   

    // Bind DataGrid  --Begin
    for (int i=0; i<this.dlList.Items.Count; i++)
    {
        Label lblFloor  = this.dlList.Items[i].FindControl("lblFloor") as Label;
        DataGrid dgList = this.dlList.Items[i].FindControl("dgList") as DataGrid;    // 隐藏显示 DataGrid 列
        for (int j=0; j<dgList.Columns.Count; j++)
        {
            if (j <= MonthEndDay)
            {
                dgList.Columns[j].Visible = true;
            }
            else
            {
                dgList.Columns[j].Visible = false;
            }
        }    DataTable dtTemp = new DataTable();
        dtTemp = dtBug.Clone();    DataRow[] drDataGrid = dtBug.Select("FloorDesc='" + lblFloor.Text + "'", "BugDesc"); 
        foreach (DataRow dr in drDataGrid)
        {
            dtTemp.ImportRow(dr);
        }    DataRow[] drSample = dtSample.Select("FloorDesc='" + lblFloor.Text + "'", "BugCode");
        foreach (DataRow dr in drSample)
        {
            dtTemp.ImportRow(dr);
        }
            
        dgList.DataSource = dtTemp;
        dgList.DataBind();
    }
    // Bind DataGrid  --End
      

  3.   

    头痛啊,我太菜了,看起头痛,
    谢谢你啊``````````NekChan(骑蜗牛看星星) 大哥!
    hanchi8008(寒池) 
    大哥,我就是不OK啊`````!555555555555555
      

  4.   

    我是在DATAGRID 里建立一个模板列,在模版列里加入的一个DATAGRID
    在视图状态下进行的```````5555555555555555!
    private void Get_Classname()
    {
    GetUser_Info username=new GetUser_Info();
    string user=username.GetUserName();//获取登陆者名称给创建者名称  SqlConnection myConnection = new SqlConnection(ConnectionString);//取连接字符串,建立连接
    SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();

    SqlDataAdapter1.SelectCommand=new SqlCommand("SELECT * FROM grbg_gyjh_class where cruser='"+user.Trim()+"' ORDER BY id DESC ",myConnection);

    DataSet DataSet1=new DataSet();
    try
    { SqlDataAdapter1.Fill(DataSet1,"grbg_gyjh_class");
    MyDataGrid_Get_Gzjh_big.DataSource=DataSet1;
    MyDataGrid_Get_Gzjh_big.DataBind();
                //以下是邦定子DATAGRID
                    myConnection.Close();  
    myConnection.Open();
    SqlDataAdapter SqlDataAdapter2 = new SqlDataAdapter();
    SqlDataAdapter2.SelectCommand=new SqlCommand("SELECT * FROM grbg_gzjh_id where grbg_gzjh_user='"+user.Trim()+"' ORDER BY id DESC ",myConnection);
                    DataSet DataSet2=new DataSet();
    try
    {
    SqlDataAdapter2.Fill(DataSet2,"grbg_gzjh_id");   
    MyDataGrid_Get_Gzjh_samll.DataSource=DataSet2;
    MyDataGrid_Get_Gzjh_samll.DataBind();
    }
    catch(SqlException e2)
    {
                       myConnection.Close();  
    }
    finally
    {
                        myConnection.Close();  
    }
    }
    catch (SqlException e1)
    {
    Response.Write("数据库操作错误:"+e1.Message);
    }// 在此处放置用户代码以初始化页面

    finally
    {   //关闭数据库连接
    myConnection.Close();  
    }
    }

    我也知道我这样肯定不对,因为我把protected System.Web.UI.WebControls.DataGrid MyDataGrid_Get_Gzjh_samll;加到引用里,在视图状态下,就看见模板列中的MyDataGrid_Get_Gzjh_samll就报错了,说已经存在了
    但是不要这句话,生成的时候又要说MyDataGrid_Get_Gzjh_samll未引用实列`~!
    头痛啊,是不是必须建用户控件啊``````````
      

  5.   

    建用户控件可能会简单点注意把传进去的分类ID使用ViewState 保存既可