C# récupérer valeur js

Résolu/Fermé
Juduno - Modifié le 23 mai 2018 à 17:33
 Juduno - 24 mai 2018 à 12:20
Bonjour,
voilà petit problème
dans ma page j'arrive avec un grptPrestId = 38
une de mes lignes de ma page est créer comme suite
 var row = new TableRow();
      this.tblRegle.Rows.Add(row);

      var cell = new TableCell();
      row.Cells.Add(cell);
      if (grptEntiteId != null)
      {
        cell.Text = Ress.RegleEdition.LabelGroupePrestation;
      }
      else if (grptPrestId != null)
      {
        cell.Text = Ress.RegleEdition.LabelGroupePartenaire;
      }
      cell.Font.Bold = true;

      cell = new TableCell();
      row.Cells.Add(cell);
      var list = new SqlDropDownList();
      cell.Controls.Add(list);
      list.Width = Unit.Pixel(300);
      list.ID = "grpt_id";
      list.TabIndex = this._tabIndex++;

      // bind
      list.Items.Add(new ListItem("--AUCUN--", "0"));
      string sql = string.Empty;
      if (grptEntiteId != null)
      {
        sql = this.GetSqlReadGroupePrestation();
      }
      else if (grptPrestId != null)
      {
        sql = this.GetSqlReadGroupePartenaire();
      }

      using (DataSet dataSet = this.ConnexionUtil.ExecuteRequeteDataSet(sql))
      {
        foreach (DataRow r in dataSet.Tables[0].Rows)
        {
          string id = SqlConvert.ToString(r["grpt_id"]);
          list.Items.Add(new ListItem(SqlConvert.ToString(r["grpt_nom"]), id));
        }
      }

      ((DropDownList)this.tblRegle.FindControl("grpt_id")).Attributes["onchange"] += $"document.getElementById('grpt_id').innerText = this[this.selectedIndex].value;";
       string html = $"<span id='grpt_id' type='hiden'>{this.grptPrestId}<span>";
        cell.Controls.Add(new LiteralControl(html)); 
 


EDIT : Ajout du langage dans les balises de code pour avoir la coloration syntaxique...

au cas où j'ai essayé avec
 html = $"<input id='grpt_id' type='hidden' name='grpt_id'/>";


sur la page quand je modifie du coup le dropdownLIst je vois bien mon grptPrestId qui prend la value de celui que j'ai sélect mais quand j'essaye d'insérer en bdd mon grptPrestId est = 38 et non par exemple 111 qui est un des index que je peux select dans le dropdown liste

au cas où c'est pas moi qui est choisie de faire comme ça pour faire la page par contre on m'impose de faire comme ça

si une personne peux m'aider merci d'avance

1 réponse

merci à moi faut faire comme ce ci (adapter à mon code voir plus haut )
if (this.grptPrestId != string.Empty)
          {
            this.grptPrestId = this.RequestToInt32("grpt_id",0).ToString();
          }
          else if (this.grptEntiteId != string.Empty)
          {
            this.grptEntiteId = this.RequestToInt32("grpt_id", 0).ToString();
          }
          else
          {
            this.grptPrestId = this.RequestToInt32("grpt_id_prest", 0).ToString();
            this.grptEntiteId = this.RequestToInt32("grpt_id_enti", 0).ToString();
          }
0