2
I am having problems when displaying a gridView, it is not displaying the right data, it seems that this trying to display vertically, I have already changed the property Gridline to horizontal, Both and now this Name, like another gridView that I have working. This gridView of mine is being populated with information coming from the database. This is my gridView:
<asp:GridView ID="gridacao" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" ForeColor="#333333" GridLines="None" ToolTip="Valores Atualizados das ações" Width="344px">
<AlternatingRowStyle BackColor="Gainsboro" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
in part . Cs this so:
public partial class ExibeAcao : System.Web.UI.Page
{
string cd;
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
exibirAcao();
}
}
catch (Exception ce1)
{
throw new Exception(ce1.Message.ToString());
}
}
private void exibirAcao()
{
try
{
cd = "PETR4";
Trataformes tf = new Trataformes();
this.gridacao = tf.mostraAcao(cd, ref gridacao);
}
catch (Exception e2)
{
throw new Exception(e2.Message.ToString());
}
}
protected void gridacao_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
The Show() method is this:
public GridView mostraAcao(string cd, ref GridView gv)
{
try
{
ManipulaBanco mp = new ManipulaBanco();
return mp.exibeAcao(cd, ref gv);
}
catch (Exception e)
{
throw new Exception(e.Message.ToString());
}
}
and the method removed from the database is this:
public GridView exibeAcao(string cod, ref GridView tb)
{
try
{
bancotccEntities bc = new bancotccEntities();
var pa = from ac in bc.acao
where ac.codigo == cod
select new
{
Ação = ac.codigo,
Empresa = ac.empresa,
Tipo = ac.tipo,
Data = ac.data,
Hora = ac.hora,
Abertura = ac.abertura,
Maxima = ac.maxima,
Minima = ac.minima,
Média = ac.medio,
Valor = ac.fechamento,
fechamento_Ontem = ac.f_anterior,
Volume_de_Ações = ac.volume,
Valor_Negociado = ac.v_financeiro,
Variação = ac.variacao,
Fase = ac.fase
};
tb.DataSource = pa.ToString();
tb.DataBind();
return tb;
}
catch (Exception e)
{
throw new Exception(e.Message.ToString());
}
}
am getting the result below:
I’d like it to be displayed horizontally, someone knows how?
tb.DataSource = pa.ToString();
It’s wrong here, it wouldn’t be;tb.DataSource = pa.ToList();
– user6026
It is!! Wrong method, only now it is not displaying anything.
– user9090
Breakpoint is the only solution ...
– user6026
First thing you do is this
AutoGenerateColumns="False"
placeAutoGenerateColumns="True"
if carrying was that.!– user6026