Ajouter un commentaire

vince23

Bonjour,

Essaye ceci :

    protected void Page_Load(object sender, EventArgs e)
    {
        // initialisation
        this.dgAllocation.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(dgAllocation_UpdateCommand);
        this.dgAllocation.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(dgAllocation_DeleteCommand);
        this.dgAllocation.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(dgAllocation_EditCommand);
        chargementDuDatagrid();
    }

    private void dgAllocation_DeleteCommand(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
        // delete
        // puis on repasse en mode normal
        dgAllocation.EditItemIndex = -1
        chargementDuDatagrid();
    }

    private void dgAllocation_EditCommand(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
        // edit
        dgAllocation.EditItemIndex = e.Item.ItemIndex;
        chargementDuDatagrid();
    }

    private void dgAllocation_UpdateCommand(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
        // update
        // puis on repasse en mode normal
        dgAllocation.EditItemIndex = -1
        chargementDuDatagrid();
    }

    public void chargementDuDatagrid()
    {
        // chargement du datatgrid
        DataSet dt = new DataSet();

        DataTable table = new DataTable();
        DataColumn column = new DataColumn("Type");
        table.Columns.Add(column);
        DataColumn column1 = new DataColumn("Montant");
        table.Columns.Add(column1);

        DataRow row = table.NewRow();
        row["Type"] = "type1";
        row["Montant"] = "montant1";
        table.Rows.Add(row);
        dt.Tables.Add(table);
        dgAllocation.DataSource = dt;
        dgAllocation.DataBind();
    }

Il faut lier les méthodes aux évènements. Dans le page load, on initialise les différentes commandes possibles (update, delete, etc.). Ainsi, une méthode précise est executée au bon moment.

pour ton erreur, je l'ai eu aussi. En fait, c'est parce que tu fais :
datagrid.EditItemIndex = e.Item.ItemIndex ;
et derrière tu ne recharges pas ton datagrid

Donc lorsque tu le fais la deuxième fois, tu lui demandes de passer dans un état dans lequel il est, d'où l'erreur.

Il faut donc, après une modification de l'attribut EditItemIndex, recharger ton datagrid

Filtered HTML

Plain text

CAPTCHA
Cette question permet de vérifier que vous n'êtes pas un robot spammeur :-)
     J  ZZZZZ   AA   RRRR    QQQ   
J Z A A R R Q Q
J Z AAAA RRRR Q Q
J J Z A A R R Q QQ
JJJ ZZZZZ A A R RR QQQQ
Q