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

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

    1. <tfoot id='ABRLs'></tfoot>

      • <bdo id='ABRLs'></bdo><ul id='ABRLs'></ul>
    2. asp.net中的列表框没有得到选定的项目

      时间:2023-10-07

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

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

              • 本文介绍了asp.net中的列表框没有得到选定的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有多个下拉菜单和我网页中的列表框.

                I have multiple dropdown & listbox in my webpage.

                我正在尝试从 lstCatID 列表框中获取 CategoryID 列表,我可以使用类别名称填充列表框.

                I am trying to get a list of CategoryID from a lstCatID listbox i am able to populate the listbox with category name.

                如果我在第一次尝试时没记错,我的代码运行良好,之后我做了一些更改,然后它声明总是选择第一个项目 x 时间

                If i remember correctly in first attempt my code worked fine, after that i made some change then it stated to always get the first item selected x No. of time

                <asp:ListBox ID="lstCatID" runat="server" DataTextField="CategoryName" 
                                DataValueField="CategoryID" SelectionMode="Multiple" CssClass="lstListBox">
                 </asp:ListBox>
                
                
                
                protected void Button1_Click(object sender, EventArgs e)
                {
                    string CatID = string.Empty;
                    foreach (ListItem li in lstCatID.Items)
                    {
                        if (li.Selected == true)
                        {
                           // Response.Write();
                            CatID += lstCatID.SelectedItem.Value + ",";
                        }
                    }
                    Response.Write(CatID);
                }
                

                我不确定出了什么问题,我检查了 MSDN,它显示的方法完全相同.

                I am not sure what is going wrong i checkd MSDN it show exactly the same way of doing it.

                可能是我做错了什么.

                只需使用 Firefox 添加,我就能看到多个选定的值具有选定的属性.

                Just to add using firefox i am able to see multiple selected value have selected property.

                <option value="3" selected="selected">One</option>
                <option value="2">Two</option>
                <option value="29" selected="selected">Three</option>
                <option value="25" selected="selected">Four</option>
                <option value="22" >Five</option>
                

                在这种情况下,我的输出将是 3,3,3

                My output in this case will be 3,3,3

                我会很感激这方面的帮助

                I would appreciate help in this regard

                推荐答案

                您每次都将其设置为相同的值:

                You are setting it to the same value every time:

                foreach (ListItem li in lstCatID.Items)
                {
                    if (li.Selected == true)
                    {
                       // you are always using lstCatID.SelectedItem.Value.
                        CatID += lstCatID.SelectedItem.Value + ",";
                    }
                }
                

                当你真正想要你的循环中被选中的项目的值时:

                When you actually want the value of the item in your loop that is selected:

                foreach (ListItem li in lstCatID.Items)
                {
                    if (li.Selected == true)
                    {
                        // get the value of the item in your loop
                        CatID += li.Value + ",";
                    }
                }
                

                这篇关于asp.net中的列表框没有得到选定的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:将项目从一个列表框移动到另一个 下一篇:我想在 winforms 列表框控件中检测项目双击.[如何处理点击空白区域?]

                相关文章

                  <bdo id='db2pD'></bdo><ul id='db2pD'></ul>

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

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

                  2. <legend id='db2pD'><style id='db2pD'><dir id='db2pD'><q id='db2pD'></q></dir></style></legend>