Unable to get the selected item value of Listbox in codebehind

Joined
Nov 2, 2006
Messages
1
Reaction score
0
Hello friends,

I got very interesting problem. i have two list boxes, when i select an item from one list box and click the button it should be transfered from one list box to another one. Please dont give me the code to do this..... I have the code It was working for my previous application but the same code it not working now for these list boxes. i didn't find any difference. actually the problem is, The selected item value i am getting in coe behind is false(actually it should be true.)...
I would be really Thankfull if any would help me in this regard.
Thanks in advance.......

i am also giving the code check this it may help you to solve the problem.

Code in aspx file


<table cellSpacing="0" cellPadding="0" width="85%" border="0">
<tr>
<td vAlign="top" width="100%">
<asp:ListBox id="ListProjectAttributesFrom" tabIndex="1" runat="server" SelectionMode="Multiple" Visible="true" Width="200px" Height="100px">
<asp:ListItem></asp:ListItem>
</asp:ListBox></td>
<td>
<asp:button id="Next" Runat="server" CssClass="buttonStyle" Text=">" Width="50"></asp:button></div>
<td vAlign="top"><asp:listbox id="ListProjectAttributesTo" SelectionMode="Multiple" Runat="server" CssClass="ForListBox"
ONCHANGE="test()" Width="200" Height="100" AutoPostBack="True">
<asp:ListItem></asp:ListItem>
</asp:listbox></td>
<td>&nbsp;</td>
</tr>
</table>



Code For buttonclikck in Codebehind ( in C#.net ):


private void Next_Click(object sender, System.EventArgs e)
{
foreach(ListItem item in ListProjectAttributesFrom.Items)
{
if (item.Selected == true)
{
if (!ListProjectAttributesTo.Items.Contains(item))
{
ListProjectAttributesTo.Items.Add(item);
//BtnAddSave.Enabled=true;
}
}
}
foreach(ListItem item in ListProjectAttributesTo.Items)
{
ListProjectAttributesFrom.Items.Remove(item);
if (item.Selected == true)
{
item.Selected=false;
}

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top