Bonjour,
je suis entrain de faire ma première application en ASP.net ,mon problème c'est que j 'ai crée une table htmltable sous ASP.net (c#) , que je la remplie de ma base de donnée , mais je veux pour chaque ligne avoir un control alors j 'ai ajouter une colonne contenant des boutons ,quand je clique sur un bouton de la ligne i une requête update doit être exécutée mais j ai po pu le faire .
voici mon code :
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection oConnexion = new SqlConnection("Data Source=DELL-PC\\SQLEXPRESS;Initial Catalog=db_ocp;Integrated Security=True");
oConnexion.Open();
// Définition de la requête à exécuter
SqlCommand oCommand = new SqlCommand("SELECT * FROM pane where etat= 1 and num_matricule=999 order by id_panne asc ", oConnexion);
SqlDataReader drUtilisateur = oCommand.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(drUtilisateur);
HtmlTable t = new HtmlTable();
t.Border = 2;
t.BorderColor = "skyblue";
t.Width = "100%";
for (int i = 0; i < dt.Rows.Count; i++)
{
HtmlTableRow r = new HtmlTableRow();
t.Rows.Add(r);
for (int j = 0; j < dt.Columns.Count; j++)
{
if (j == 5)
{
if (dt.Rows[i][j].ToString() == "0")
{
HtmlTableCell c = new HtmlTableCell();
c.BgColor = " #ffffff ";
c.InnerHtml = "salut";
t.Rows[i].Cells.Add(c);
}
else
{
HtmlTableCell c = new HtmlTableCell();
c.InnerHtml = "çava??";
t.Rows[i].Cells.Add(c);
}
}
else
{
HtmlTableCell c = new HtmlTableCell();
c.InnerHtml = dt.Rows[i][j].ToString();
t.Rows[i].Cells.Add(c);
}
}
HtmlTableCell d = new HtmlTableCell();
Button ButApercu = new Button();
ButApercu.Text = "Confirmer";
ButApercu.Visible = true;
// ButApercu.ID = "butapercu1";
// ButApercu.Attributes.Add("onclik", "alert(hi);");
ButApercu.OnClientClick = "click(dt.Rows[i][0]);";
t.Rows[0].Cells.Add(d);
d.Controls.Add(ButApercu);
Page.Controls.Add(t);
form1.Controls.Add(t);
}
}
void click(int l)
{
SqlConnection oConnexion = new SqlConnection("Data Source=DELL-PC\\SQLEXPRESS;Initial Catalog=db_ocp;Integrated Security=True");
oConnexion.Open();
// Définition de la requête à exécuter
SqlCommand oCommand = new SqlCommand("update pane set etat='2'where id_panne=l", oConnexion);
SqlDataReader drUtilisateur = oCommand.ExecuteReader();}}