Change Gridview

Asked

Viewed 123 times

0

I’m having a problem changing some information, in case I need to change two columns of a gridview, but they are coming directly from a database

inserir a descrição da imagem aqui

I need to change these two fields(Id_category and Desc_category)

Form:

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

Business layer

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

}

Dice:

//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;
}

1 answer

2


it appears to be winforms, and you want to change the column title.

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

ID_Categoria as "Categoria",

or modified from DataGridView dynamically:

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

or manually places the columns in the DataGridView, disables the AutoGenerateRows and associates your column of the DataTable by property DataPropertyName. This last, you can do by the graphical interface of the visual studio.

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.