• <small id='rV33F'></small><noframes id='rV33F'>

      <i id='rV33F'><tr id='rV33F'><dt id='rV33F'><q id='rV33F'><span id='rV33F'><b id='rV33F'><form id='rV33F'><ins id='rV33F'></ins><ul id='rV33F'></ul><sub id='rV33F'></sub></form><legend id='rV33F'></legend><bdo id='rV33F'><pre id='rV33F'><center id='rV33F'></center></pre></bdo></b><th id='rV33F'></th></span></q></dt></tr></i><div id='rV33F'><tfoot id='rV33F'></tfoot><dl id='rV33F'><fieldset id='rV33F'></fieldset></dl></div>

      • <bdo id='rV33F'></bdo><ul id='rV33F'></ul>
      <legend id='rV33F'><style id='rV33F'><dir id='rV33F'><q id='rV33F'></q></dir></style></legend>
      <tfoot id='rV33F'></tfoot>

      1. ASP.NET:列表框数据源和数据绑定

        时间:2023-10-08
          <tbody id='3BOY2'></tbody>
        <i id='3BOY2'><tr id='3BOY2'><dt id='3BOY2'><q id='3BOY2'><span id='3BOY2'><b id='3BOY2'><form id='3BOY2'><ins id='3BOY2'></ins><ul id='3BOY2'></ul><sub id='3BOY2'></sub></form><legend id='3BOY2'></legend><bdo id='3BOY2'><pre id='3BOY2'><center id='3BOY2'></center></pre></bdo></b><th id='3BOY2'></th></span></q></dt></tr></i><div id='3BOY2'><tfoot id='3BOY2'></tfoot><dl id='3BOY2'><fieldset id='3BOY2'></fieldset></dl></div>

            <bdo id='3BOY2'></bdo><ul id='3BOY2'></ul>
          • <tfoot id='3BOY2'></tfoot>

                  <legend id='3BOY2'><style id='3BOY2'><dir id='3BOY2'><q id='3BOY2'></q></dir></style></legend>
                1. <small id='3BOY2'></small><noframes id='3BOY2'>

                  本文介绍了ASP.NET:列表框数据源和数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 .aspx 页面上有一个空列表框

                  I have an empty listbox on .aspx page

                  lstbx_confiredLevel1List
                  

                  我正在以编程方式生成两个列表

                  I am generating two lists programatically

                  List<String> l1ListText = new List<string>(); //holds the text 
                  List<String> l1ListValue = new List<string>();//holds the value linked to the text
                  

                  我想用上述值和文本在 .aspx 页面上加载 lstbx_confiredLevel1List 列表框.所以我正在做以下事情:

                  I want to load lstbx_confiredLevel1List list box on .aspx page with above values and text. So i am doing following:

                  lstbx_confiredLevel1List.DataSource = l1ListText;
                  lstbx_confiredLevel1List.DataTextField = l1ListText.ToString();
                  lstbx_confiredLevel1List.DataValueField = l1ListValue.ToString();
                  lstbx_confiredLevel1List.DataBind();
                  

                  但它不会使用 l1ListTextl1ListValue 加载 lstbx_confiredLevel1List.

                  but it does not load the lstbx_confiredLevel1List with l1ListText and l1ListValue.

                  有什么想法吗?

                  推荐答案

                  为什么不用和DataSource一样的集合呢?它只需要具有键和值的两个属性.你可以使用 Dictionary<string, string>:

                  Why don't you use the same collection as DataSource? It just needs to have two properties for the key and the value. You could f.e. use a Dictionary<string, string>:

                  var entries = new Dictionary<string, string>();
                  // fill it here
                  lstbx_confiredLevel1List.DataSource = entries;
                  lstbx_confiredLevel1List.DataTextField = "Value";
                  lstbx_confiredLevel1List.DataValueField = "Key";
                  lstbx_confiredLevel1List.DataBind();
                  

                  您还可以使用匿名类型或自定义类.

                  You can also use an anonymous type or a custom class.

                  假设您已经拥有这些列表并且需要将它们用作数据源.您可以即时创建 Dictionary:

                  Assuming that you have already these lists and you need to use them as DataSource. You could create a Dictionary on the fly:

                  Dictionary<string, string> dataSource = l1ListText
                             .Zip(l1ListValue, (lText, lValue) => new { lText, lValue })
                             .ToDictionary(x => x.lValue, x => x.lText);
                  lstbx_confiredLevel1List.DataSource = dataSource;
                  

                  这篇关于ASP.NET:列表框数据源和数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将文本文件加载到列表框中 下一篇:列表框中的选定项为空

                  相关文章

                  <legend id='qoyL4'><style id='qoyL4'><dir id='qoyL4'><q id='qoyL4'></q></dir></style></legend>

                    <tfoot id='qoyL4'></tfoot>

                      <small id='qoyL4'></small><noframes id='qoyL4'>

                      • <bdo id='qoyL4'></bdo><ul id='qoyL4'></ul>
                    1. <i id='qoyL4'><tr id='qoyL4'><dt id='qoyL4'><q id='qoyL4'><span id='qoyL4'><b id='qoyL4'><form id='qoyL4'><ins id='qoyL4'></ins><ul id='qoyL4'></ul><sub id='qoyL4'></sub></form><legend id='qoyL4'></legend><bdo id='qoyL4'><pre id='qoyL4'><center id='qoyL4'></center></pre></bdo></b><th id='qoyL4'></th></span></q></dt></tr></i><div id='qoyL4'><tfoot id='qoyL4'></tfoot><dl id='qoyL4'><fieldset id='qoyL4'></fieldset></dl></div>