i have a gridview that displays query data from 1 table after the user presses a button with a code behind query, this gridview had autogeneratecolumns = false and i added the BoundField DataField header texts myself, for example, the first column in the db had the name "prd_nome" and i changed it to "nome", everything worked as it was supposed to.
now i've created a another table in the db, with a different name and different column names as well, i've also added another button with a code behind query to get data from that table but in order to display the data now the autogeneratecolumns = true, i tested the button and it works, however the header texts are the same as the column names and the ID column is also showing for both queries.
how do i hard code the header texts to what i want and how do i hide the ID column? via labels? via boundfield datafields? via the AS sql operator? if anyone could help me, i would appreciate because i'm a c# novice
here's the current gridview asp code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true"></asp:GridView>
here's the code of the button that passes a query from the first table:
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection(GetConnectionString());
connection.Open();
SqlCommand sqlCmd = new SqlCommand("SELECT * FROM [ERPDQ].[dbo].[prd] WHERE prd_desc LIKE ('torta%')", connection);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
connection.Close();
}
and here's the code from the button that passes a query regarding the second table:
protected void Button6_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection(GetConnectionString());
connection.Open();
SqlCommand sqlCmd = new SqlCommand("SELECT * FROM [ERPDQ].[dbo].[outra]", connection);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
connection.Close();
}
}