1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| public partial class _Default : System.Web.UI.Page
{
static List<MonObjet> lstTest = new List<MonObjet>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lstTest = ObjectList(); // Bind lstTest via la database
DataList1.DataSource = lstTest;
DataList1.DataBind();
Timer1.Interval = 1000;
}
// c'est 2 lignes sont nécessaires pour que la DataList soit mise à jour automatiquement mais le bouton ne fonctionne pas dans ce cas là.... (via les breakpoint on voit que ça ne rentre même pas dans la méthode : DataListCommand)
// si commenté le bouton fonctionne mais rien ne se met à jour tout seul
// si non commenté les infos se mettent à jour mais le bouton ne fonctionne pas
//DataList1.DataSource = lstTest;
//DataList1.DataBind();
}
protected void Timer1Tick(object sender, EventArgs e)
{
// même nul doit exister
}
protected void DataListCommand(object sender, DataListCommandEventArgs e)
{
if (e.CommandName == "action")
{
Label lblName = (Label)e.Item.FindControl("lblName");
int index = lstTest.FindIndex(item => item.m_Name == lblName.Text);
/*
Bout de code qui fait son tintouin
*/
// réaffiche la DataList
DataList1.DataSource = lstDateTest;
DataList1.DataBind();
}
}
// appellée lors du chargement (et rechargement !) de la page pour remplir la DataList
protected void dlItemDataBound(object sender, DataListItemEventArgs e)
{
Label lblName = (Label)e.Item.FindControl("lblName");
lblName.Text = ((MonObjet)e.Item.DataItem).m_Name;
Label lblInfo = (Label)e.Item.FindControl("lblInfo");
lblInfo.Text = ((MonObjet)e.Item.DataItem).m_Info;
}
} |
Partager