OVH Cloud OVH Cloud

l'objet CommandEventHandler

1 réponse
Avatar
lorenzo
Bonjour,

J'ai créer dynamiquement des champs textbox que je remplis avec une base de données SQL Server et des boutons. Je voudrais en cliquant sur un bouton faire un update de ma base. Mon souci est que je n'arrive pas à faire fonctionner le bouton.
Voici mon code :

this._imgAddOk = new Button();
this._imgAddOk.ID="imgAddOk";
this._imgAddOk.Text ="Ok";
this._imgAddOk.Width = new Unit("100px");
this._imgAddOk.Height = new Unit("30px");
this._imgAddOk.Command += new System.Web.UI.WebControls.CommandEventHandler(this.imgAddOk_Command);

// Bouton Cancel
this._imgAddCancel = new Button();
this._imgAddCancel.ID = "imgAddCancel";
this._imgAddCancel.Text = "Cancel";
this._imgAddCancel.Width = new Unit("100px");
this._imgAddCancel.Height = new Unit("30px");
this._imgAddCancel.Command += new System.Web.UI.WebControls.CommandEventHandler(this.imgAddCancel_Command);


Literal lcTemp1 = new Literal();
lcTemp1.Text = "<tr><td colspan=\"2\" valign=\"middle\" align=\"center\">";
this.panelAdd.Controls.Add(lcTemp1);
this.panelAdd.Controls.Add(this._imgAddOk);
Literal lcTemp2 = new Literal();
lcTemp2.Text = " ";
this.panelAdd.Controls.Add(lcTemp2);
this.panelAdd.Controls.Add(this._imgAddCancel);
Literal lcTemp3 = new Literal();
lcTemp3.Text = "</td></tr>";
this.panelAdd.Controls.Add(lcTemp3);
Literal lcTop = new Literal();
lcTop.Text = "</Table>";
this.panelAdd.Controls.Add(lcTop);

private void imgAddOk_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{
}

private void imgAddCancel_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{
}

Merci pour votre aide

Lorenzo

1 réponse

Avatar
pc152
tu a fait un bouton ok!

mais tu ne lui a pas fait de fonction click,donc comment veux tu qu'il
reagise

this.imgAddOK.Click += new System.EventHandler(this.button1_Click);

private void button1_Click(object sender, System.EventArgs e)

{



}



voila je pense que ca iras mieux comme ca

"lorenzo" a écrit dans le message de
news:
Bonjour,

J'ai créer dynamiquement des champs textbox que je remplis avec une base


de données SQL Server et des boutons. Je voudrais en cliquant sur un bouton
faire un update de ma base. Mon souci est que je n'arrive pas à faire
fonctionner le bouton.
Voici mon code :

this._imgAddOk = new Button();
this._imgAddOk.ID="imgAddOk";
this._imgAddOk.Text ="Ok";
this._imgAddOk.Width = new Unit("100px");
this._imgAddOk.Height = new Unit("30px");
this._imgAddOk.Command += new


System.Web.UI.WebControls.CommandEventHandler(this.imgAddOk_Command);

// Bouton Cancel
this._imgAddCancel = new Button();
this._imgAddCancel.ID = "imgAddCancel";
this._imgAddCancel.Text = "Cancel";
this._imgAddCancel.Width = new Unit("100px");
this._imgAddCancel.Height = new Unit("30px");
this._imgAddCancel.Command += new


System.Web.UI.WebControls.CommandEventHandler(this.imgAddCancel_Command);


Literal lcTemp1 = new Literal();
lcTemp1.Text = "<tr><td colspan="2" valign="middle"


align="center">";
this.panelAdd.Controls.Add(lcTemp1);
this.panelAdd.Controls.Add(this._imgAddOk);
Literal lcTemp2 = new Literal();
lcTemp2.Text = " ";
this.panelAdd.Controls.Add(lcTemp2);
this.panelAdd.Controls.Add(this._imgAddCancel);
Literal lcTemp3 = new Literal();
lcTemp3.Text = "</td></tr>";
this.panelAdd.Controls.Add(lcTemp3);
Literal lcTop = new Literal();
lcTop.Text = "</Table>";
this.panelAdd.Controls.Add(lcTop);

private void imgAddOk_Command(object sender,


System.Web.UI.WebControls.CommandEventArgs e)
{
}

private void imgAddCancel_Command(object sender,


System.Web.UI.WebControls.CommandEventArgs e)
{
}

Merci pour votre aide

Lorenzo