Change GridView

0

Ineedtochangethesetwofields(category_idanddesc_category)

Form:

private void Mostrar()
{
this.datalista.DataSource = NCategoria.Mostrar();
}

Business layer

//Método Mostrar
public static DataTable Mostrar()
{
return new DCategoria().Mostrar();

}

Data:

//metodo mostrar

public DataTable Mostrar()
{
DataTable DtResultado = new DataTable("categoria");
SqlConnection SqlCon = new SqlConnection();
try
{
	SqlCon.ConnectionString = Conexao.Cn;
	SqlCommand SqlCmd = new SqlCommand();
	SqlCmd.Connection = SqlCon;
	SqlCmd.CommandText = "spmostrar";
	SqlCmd.CommandType = CommandType.StoredProcedure;
	SqlDataAdapter sqlDat = new SqlDataAdapter(SqlCmd);
	sqlDat.Fill(DtResultado);
}
catch
{
	DtResultado = null;
}
return DtResultado;
}
    
asked by anonymous 26.09.2017 / 02:20

1 answer

2

Apparently it seems to be winforms, and you want to change the column heading.

You can do three ways, or change in the storedProcedure by putting alias:

ID_Categoria as "Categoria",

or change DataGridView dynamically:

this.datalista.Columns[1].HeaderText = "Categoria";

or manually places the columns in the DataGridView , disables the AutoGenerateRows of the control and associates its DataTable column with the DataPropertyName property. The latter, you can do through the graphical interface of visual studio.

    
26.09.2017 / 02:54