Click here to Skip to main content
15,908,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,
In My Application my first ListBox is populating on selected index of Dropdown and then According to Multiple Selected Item in my First Listbox i am filling SecondList box.

The Problem is That Second Listbox always taking first item in FirstList Box even it is not selected,

to populate the first list box my code is
C#
protected void ddlSkillType_SelectedIndexChanged(object sender, EventArgs e)
       {
           List<TblSkillType> lstSkillType = ServiceAccess.GetProxy().GetSkillType();
           List<TblSkill> lstSkill = ServiceAccess.GetProxy().GetAllSkill();
           List<TblSkillDetail> lstSkillDetails = ServiceAccess.GetProxy().GetAllSkillDtls();
           var skill = (from a in lstSkillType
                        from b in lstSkill
                        from c in lstSkillDetails
                        where a.SkillTypeId == Convert.ToInt32(ddlSkillType.SelectedValue) && a.SkillTypeId == b.SkillTypeId && b.SkillId == c.SkillId
                        select new { b.SkillId, c.SkillName }).ToList();
           lstboxSkill.DataSource = skill;
           lstboxSkill.DataTextField = "SkillName";
           lstboxSkill.DataValueField = "SkillId";
           lstboxSkill.DataBind();
       }


and for filling second listbib my code is

C#
 protected void imgbtnMoveRightListBox_Click(object sender, ImageClickEventArgs e)
        {
            for (int i = 0; i < lstboxSkill.Items.Count; i++)
            {
                if (lstboxSkill.Items[i].Selected)
                {
                    lstBBoxSkill2.Items.Add(lstboxSkill.Items[i]);
                }

            }
}


i amchecking it using break point and i found Second ListBox Always taking fistitem of firstList box even it is not selected.
and after multiple selecting in first listbox,second listbox fills with multiple fistitem of first listbox
i don't know what is the problem.
Kindly help me to fix it.
Thanks In advance...!!

My aspx Code
ASP.NET
 <td>
                                <asp:DropDownList ID="ddlSkillType" runat="server" CssClass="Dropdownlist myddl" OnSelectedIndexChanged="ddlSkillType_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
                            </td>
<td>
                                
                                <table class="tblListBoxContainer">
                                    <colgroup>
                                        <col class="col1" />
                                        <col class="col2" />
                                        <col class="col3" />
                                    </colgroup>
                                    <tr>
                                        <td>
                                            <asp:ListBox ID="lstboxSkill" runat="server" CssClass="ListBox" Rows="5" SelectionMode="Multiple" OnSelectedIndexChanged="lstboxSkill_SelectedIndexChanged"></asp:ListBox>
                                        </td>
                                        <td>
                                            <div style="width: 25px;">
                                                <asp:ImageButton ID="imgbtnMoveRightListBox" runat="server" ImageUrl="~/images/Common/next-blue.png" Height="10" Width="20" OnClick="imgbtnMoveRightListBox_Click" />
                                                <br />
                                                <br />
                                                <asp:ImageButton ID="imgbtnMoveLeftListBox" runat="server" ImageUrl="~/images/Common/back-blue.png" Height="10" Width="20" OnClick="imgbtnMoveLeftListBox_Click" />
                                            </div>
                                        </td>
                                        <td>
                                            <asp:ListBox ID="lstBBoxSkill2" runat="server" CssClass="ListBox" Rows="5" SelectionMode="Multiple"></asp:ListBox>
                                        </td>
                                        <td>
                                            <asp:Label ID="lbltxt" runat="server" CssClass="Label"></asp:Label>
                                        </td>
                                    </tr>
                                </table>

                            </td>
Posted
Updated 6-Feb-14 23:15pm
v2
Comments
Karthik_Mahalingam 7-Feb-14 5:04am    
post your aspx code
Prasad Avunoori 10-Feb-14 2:30am    
What is the count of listbox1 when you click on imgbtnMoveRightListBox?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900