Pass ASP.Net GridView from one page to another page

前端 未结 6 1577
终归单人心
终归单人心 2021-01-12 13:59

I want to pass all the gridview value into another page I have one gridview in PatientDetails.aspx page and one button as below



        
6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-12 14:53

    I found some solution:

    In Source aspx after grid databind:

    Session["gridtoexcel"] =  yourgrid;
    

    In destination aspx

     var grid = ((GridView)Session["gridtoexcel"]);
    
                gridToExcel.Columns.Clear();
                foreach (DataControlField col in grid.Columns)
                      gridToExcel.Columns.Add(col);
                
                gridToExcel.DataSource = grid.DataSource;
                gridToExcel.DataBind();
    
    

    this way i can 'clone' exact grid to another page. if you need some css style don't forget of add them in destination page

    PS: gridToExcel is your destination grid

提交回复
热议问题