public GridView exibeCarteira(string cepf, ref GridView tb)
{
try
{
bancotccEntities bc = new bancotccEntities();
var crt = from cart in bc.carteira
where cart.cpf == cepf
select new
{
Codigo = cart.codigo,
Valor = cart.valoracao,
Quantidade = cart.qtdacao,
Total = cart.vtotalacao,
Valor_Gasto = cart.vinvestido
};
tb.DataSource = crt.ToList() ;
tb.DataBind();
return tb;
}
catch (Exception e1)
{
throw new Exception(e1.Message.ToString());
}
}
This method is called by the method:
public GridView mostraCarteira(string cpf, ref GridView gv)
{
try
{
ManipulaBanco mp = new ManipulaBanco();
return mp.exibeCarteira(cpf, ref gv);
}
catch (Exception e4)
{
throw new Exception(e4.Message.ToString());
}
}
Which is called by the method of my gridview that displays information for the user
public partial class ExibeCarteira : System.Web.UI.Page
{
string cpf;
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
exibirCarteira();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
private void exibirCarteira()
{
try
{
cpf = "98765432101";
Trataformes tf = new Trataformes();
this.gvcarteira = tf.mostraCarteira(cpf, ref gvcarteira);
}
catch (Exception e1)
{
throw new Exception(e1.Message.ToString());
}
}
protected void gvcarteira_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
My question is how can I format the information that will be displayed in each column in formats like date, money, set the amount of 0 after the comma, etc. I tried editing the columns but as they are generated automatically they do not appear to be formatted as shown below: can I add BoundField type columns and format them? even though my gridview automatically manages the columns? if it is possible I can format it in the way I need it but if it is not possible it has some other way?