Quiero llenar un Datagrid a partir de un ArrayList pero simplemente no me muestra nada
Código:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CFE
{
/// <summary>
/// Summary description for WebForm3.
/// </summary>
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
//if(!IsPostBack)
//{
BindGrid();
//}
}
private void InitializeComponent()
{
}
void BindGrid() {
ArrayList contenido = new ArrayList();
contenido.Add(new Book(1,"ASP.Net en 21 Lecciones Avanzadas"));
contenido.Add(new Book(2,"ASP.Net en 30 Lecciones Avanzadas"));
DataGrid1.DataSource = contenido;
DataGrid1.DataBind();
}
}
}
public class Book
{
private int id;
private string name;
public Book(int id, string name)
{
this.id=id;
this.name=name;
}
public int BookId { get { return this.id; }}
public string BookName { get { return this.name; }}
}
Y el DataGrid:
Código:
<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:BoundColumn DataField="BookId" HeaderText="ID"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
Q le ven de raro?