在不改sql语句和数据库表的情况下,使绑定到gridview中的数据进行换行

//将表中要换行的数据先放到临时变量中

    protected void exchangeRow(DataRow dataRow, DataRow tempRow)
    {
        tempRow["id"] = dataRow["id"];
        tempRow["name"] = dataRow["name"];
        tempRow["descript"] = dataRow["descript"];
    }

循环表,将表中的数据进行换行

 string rowindex = ((GridViewRow)((Button)sender).Parent.Parent).RowIndex.ToString();

 DataRow dr = dt.NewRow();
 exchangeRow(dt.Rows[int.Parse(rowindex) - 1], dr);
 exchangeRow(dt.Rows[int.Parse(rowindex)],dtRole.Rows[int.Parse(rowindex) - 1]);
 exchangeRow(dr,dt.Rows[int.Parse(rowindex) - 1]);

gridview.datasource=dt;

gridview.databind();

原文地址:https://www.cnblogs.com/songling/p/1979403.html