0

我需要一个带有组的列表框,为此我在页面中放置了一个文字控件,并使用 HTMLTextWriter 向文字控件呈现了一个选择控件。它完美呈现。

问题是我无法从 Request.Form 对象中获取选择控件。Request.Form 中缺少选择控件的 id。

为什么会这样,我怎样才能在后面的代码中获得用户选择?下面给出的代码。

Dictionary<string,List<string>> locations =  GetLocations();

      StringWriter stringWriter = new StringWriter();
      HtmlTextWriter html = new HtmlTextWriter(stringWriter);

      html.AddAttribute(HtmlTextWriterAttribute.Multiple, "multiple");
      html.AddAttribute(HtmlTextWriterAttribute.Id, "ddlLocations");
      html.RenderBeginTag(HtmlTextWriterTag.Select);
      foreach (string region in locations.Keys)
      {
          html.AddAttribute("label", region);
          html.RenderBeginTag("optgroup");
          //add countries
          foreach (string country in locations[region])
          {
              html.AddAttribute(HtmlTextWriterAttribute.Value, country);
              html.RenderBeginTag(HtmlTextWriterTag.Option);
              html.Write(country);

              html.RenderEndTag();//close option
          }
          html.RenderEndTag();//close optgroup

      }
      html.RenderEndTag();//close select

      literalForLocationDdl.Text = stringWriter.ToString();
4

0 回答 0