我有两个grid,gridview1,gridview2我要将gridview1里面的选择行选中后,按个BUTTON后,将该行信息添加到gridview2并显示出来然后再按hutton后提交到数据库。由于里面有列是图片列,所以没有用list而用了gridview。不知道该怎么做,请指教。使用datatable新增行也可,谢谢啊。

解决方案 »

  1.   

    这是按钮触发给GridView2里面新增一行的,目前只能是空行请大家帮忙看看该怎么写,谢谢
    protected void ImageButton1_Click2(object sender, ImageClickEventArgs e)
    {
    DataTable dt=new DataTable();
    dt.Columns.Add("Log29013");//这个是图片列,好像有问题
    dt.Columns.Add("Log29001");
    DataRow drw=dt.NewRow();
    dt.Rows.Add(drw);this.GridView2.DataSource = dt;
    this.GridView2.DataBind();}
      

  2.   

    DataTable dt=new DataTable();
    dt.Columns.Add("Log29013");//这个是图片列,好像有问题
    dt.Columns.Add("Log29001");
    DataRow drw=dt.NewRow();
    dt.Rows.Add(drw);楼主加了新行可是没有给新行的内容赋值啊当然是空的了
      

  3.   

    ...我说的是我只能写出空行,赋值什么的偶不只知道怎么写啊下面是我新写的,但是有问题
    protected void ImageButton1_Click2(object sender, ImageClickEventArgs e)
        {
            DataTable dt = new DataTable("New");        DataRow dr = dt.NewRow();        dr[1] = this.GridView1.SelectedRow.Cells[1].Text;//这行是图片行,但是出错了
            dr["Log29001"] = this.GridView1.SelectedRow.Cells[2].Text;//这样写好像也有问题,说dr里面没有该列...        dt.Rows.Add(dr);        this.GridView2.DataSource = dt;
            this.GridView2.DataBind();        
        }怎么 写比较好呢?
      

  4.   

    DataTable table=new DataTable();
    table.Columns.Add("Log29013");//这个是图片列,好像有问题
    table.Columns.Add("Log29001");
    for(int i=0;i<dt.row.count;i++)
    {
      DataRow row = table.NewRow();
      row["Log29013"]=dt.row[][].tostring();
      row["Log29001"]=dt.row[][].tostring();
      table.row.add(row);
    }
      

  5.   

    ^_^,偶现在这样写,列出来了,就是图片列不行的说protected void ImageButton1_Click2(object sender, ImageClickEventArgs e)
        {
            DataTable dt = new DataTable("New");        dt.Columns.Add(new System.Data.DataColumn("Log29013",typeof(System.String)));
            dt.Columns.Add(new System.Data.DataColumn("Log29001", typeof(System.String)));        DataRow dr = dt.NewRow();        dr[0] = this.GridView1.SelectedRow.Cells[1].Text;
            dr[1] = this.GridView1.SelectedRow.Cells[2].Text;        dt.Rows.Add(dr);
            
            this.GridView2.DataSource = dt;
            this.GridView2.DataBind();        
        }
      

  6.   

    是这样的,我在数据库里面存的是url
    然后在GridView1里面通过 ImageUrl='<%# Eval("Log29013") %>' 显示我使用dr[0] = this.GridView1.SelectedRow.Cells[1].Text;  图片只能显示XX我在考虑将增加一列隐藏的链接列
      

  7.   

    搞定了,完整代码,待会揭帖protected void ImageButton1_Click2(object sender, ImageClickEventArgs e)
        {
            DataTable dt = new DataTable("New");        dt.Columns.Add(new System.Data.DataColumn("Log29013",typeof(System.String)));
            dt.Columns.Add(new System.Data.DataColumn("Log29001", typeof(System.String)));        DataRow dr = dt.NewRow();        dr[0] = this.GridView1.DataKeys[this.GridView1.SelectedRow.RowIndex]["Log29013"].ToString();
            dr[1] = this.GridView1.SelectedRow.Cells[2].Text;        dt.Rows.Add(dr);
            
            this.GridView2.DataSource = dt;
            this.GridView2.DataBind();        
        }