控件原本纵向: id name sex 1 李工 男 改为横向显示: id 1 name 李工 sex 男 代码:
private void BindGv(string strWhere)
{
try
{
int iRecordCount = 0;
if (Session["Type"] != null)
{
iType = Convert.ToInt32(Session["Type"].ToString());
}
DataTable dt = _SaleOrderBll.GetCockpit(iType, iDateNum, "InvStyle", strWhere, "TotalAmount desc", this.AspNetPager.PageSize, this.AspNetPager.CurrentPageIndex, out iRecordCount);
this.AspNetPager.RecordCount = iRecordCount;
this.AspNetPager.DataBind();
//this.grid.DataSource = dt.DefaultView;
//this.grid.DataBind();
DataTable dts = TransformDataTable(dt);
BindDataForGridView(dts);
if (dt.Rows.Count > 0)
{
CharDateTable(dt);
}
}
catch { }
}
private void BindDataForGridView(DataTable paramDt)
{
int iColumnCount = paramDt.Columns.Count;
GridView1.ShowHeader = false;
GridView1.Columns.Clear();
for (int i = 0; i <= iColumnCount - 1; i++)
{
BoundField bf = new BoundField();
bf.DataField = paramDt.Columns[i].ColumnName;
GridView1.Columns.Add(bf);
}
GridView1.DataSource = paramDt;
GridView1.DataBind();
}
private DataTable TransformDataTable(DataTable paramDt)
{
DataTable dtResult = new DataTable();
int iRowCount = paramDt.Rows.Count;
int iColumnCount = paramDt.Columns.Count;
dtResult.Columns.Add("Head");
for (int i = 1; i <= iRowCount; i++)
{
dtResult.Columns.Add("Data" + i.ToString());
}
for (int i = 0; i <= iColumnCount - 1; i++)
{
DataRow dr = dtResult.NewRow();
dr["Head"] = paramDt.Columns[i].ColumnName;
for (int j = 1; j <= iRowCount; j++)
{
dr["Data" + j.ToString()] = paramDt.Rows[j - 1][i].ToString();
}
dtResult.Rows.Add(dr);
}
return dtResult;
}