从代码隐藏中在asp.net gridview中显示行和列中的相同数据?

时间:2018-05-09 10:24:16

标签: asp.net gridview

enter image description here在代码隐藏的asp.net gridview中显示行和列中的相同数据?

1 个答案:

答案 0 :(得分:0)

从你的问题中不清楚但是试试这个。

    //Create your Original DataSource
    DataTable dt = new DataTable();
    DataColumn dc1 = new DataColumn("col1");
    DataColumn dc2 = new DataColumn("col2");
    DataColumn dc3 = new DataColumn("col3");
    dt.Columns.Add(dc1);
    dt.Columns.Add(dc2);
    dt.Columns.Add(dc3);
    DataRow dr = dt.NewRow();
    dr[0] = "A";
    dr[01] = "B";
    dr[2] = "C";
    dt.Rows.Add(dr);
    //Adding Rows
    for (int i = 1; i < dt.Columns.Count; i++)
    {
        DataRow dr1 = dt.NewRow();
        dr1[0] = dt.Rows[0][i].ToString();
        dt.Rows.Add(dr1);
    }
    GridViewName.DataSource = dt;
    GridViewName.DataBind();