C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Transferring data from 1 list box 2 another on button click!


Posted Date: 05 Jul 2008      Total Responses: 2

Posted By: Greg       Member Level: Bronze     Points: 1



Hi,
if i want to transfer data from 1 list box 2 another on button click..ASP.Net has no option as listbox1.selecteditems.item....? I tried down dis code but 2 no avail:
int i, j;
Boolean flag = true;
for (i = ListBox2.Items.Count - 1; i >= 0; i--)
{
for (j = ListBox1.Items.Count - 1; j >= 0; j--)
{
if (ListBox2.Items[i].Text != ListBox1.Items[j].Text )
{
flag = true;
}
else
{
flag = false;
}
}
}
if (flag == true)
{
for (i = ListBox2.Items.Count - 1; i <= 0; i--)
{
ListBox1.Items.Add(ListBox2.Items[i]);
}
}
else
{
Response.Write("item alrdy exists");
}





Responses

Author: Mohammed Khaja Najmuddin    06 Jul 2008Member Level: GoldRating:     Points: 5

u r writing excess of code .for all this ur doing . bcoz in first loop every time if two values are same flag will change. n when u come to second loop the final flag value is taken .instead try this code.
for(int i= list2.items.count-1;i>=0;i--)
{
for(int j=listbox1.items.count-1;j>=0;j--)
if(listbox2.items[i].text!=listbox1.items[j].text)
listbox1.items.add(listbox2.items[i]);
else
response.write("Item Already Exist");
}
i hope u got ur solution .



Author: mohan    06 Jul 2008Member Level: SilverRating:     Points: 5

Try this code

for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected)
{
if (ListBox2.Items.Contains(ListBox1.Items[i]))
{
Response.Write("Items already exists");
}
else
{
ListBox2.Items.Add(ListBox1.Items[i].Text);
}
}
}



Post Reply
You must Sign In to post a response.
Next : adding data from 1 listbox 2 another on selectedindexchange
Previous : Xml File in Asp.net
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use