I am generating a gridview in a horizondal way. Code works fine but a dummy row insert with name of column1 and column2. How can I prevent this insertion?? My gridview code is
str = "select MachID,EmpCode from EmpDetails where EmpCode='" + empcode + "'";
DataTable dt = GetData(str);
DataTable dt2 = new DataTable();
for (int i = 0; i <= dt.Rows.Count; i++)
{
dt.Columns.Add();
}
for (int i = 0; i < dt.Columns.Count; i++)
{
dt2.Rows.Add();
dt2.Rows[i][0] = dt.Columns[i].ColumnName;
}
for (int i = 0; i < dt.Columns.Count; i++)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
dt2.Rows[i][j + 1] = dt.Rows[j][i];
}
}
gvOrders.DataSource = dt2;
gvOrders.DataBind();
My present o/p is
Column1 Column2
MachID 101
EmpCode ABC
I want to prevent this column1 and column2 row. How can I do this??
My GetData function is
private static DataTable GetData(string query)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand(query);
String constr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter sda = new SqlDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
return dt;
}