iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
I'm trying to get the selected item of a WebListBox on post back so i can add one item in a weblistbox to another WebListBox but the selected item isn't being detected selected when the button is clicked
Code below
<table cellspacing="0" cellpadding="0">
<tr valign="top">
<td>
<ISWebEssentials:WebListBox ID="WebListBox1" runat="server" Height="160px"
Width="250px" >
<Items>
<ISWebEssentials:WebListBoxItem Name="WebListBoxItem0" Text="1" />
<ISWebEssentials:WebListBoxItem Name="WebListBoxItem1" Text="2" />
<ISWebEssentials:WebListBoxItem Name="WebListBoxItem2" Text="3" />
<ISWebEssentials:WebListBoxItem Name="WebListBoxItem3" Text="4" ToolTip="4" />
</Items>
</ItemStyle>
</ISWebEssentials:WebListBox></td>
<td width="60" align="center" valign="middle">
<asp:Button ID="Button1" runat="server" Text="Add" ToolTip="Add item" onclick="btnAddItem_Click" /><br /><br />
</td>
<ISWebEssentials:WebListBox ID="WebListBox2" runat="server" Height="160px" Width="250px">
<ISWebEssentials:WebListBoxItem Name="WebListBoxItem0" Text="a" />
</tr>
</table>
Code behind
protected void btnAddItem_Click(object sender, EventArgs e)
{
foreach (WebListBoxItem wli in WebListBox1.Items)
if (wli.Selected)
WebListBox2.Items.Add(wli);
}
Hi Neill,
To add selected WebListBoxItem to another WebListBoxItem, I suggest you to use SelectedIndex property in WebListBox. SelectedIndex is also usefull because you don't have to do looping to find a selected items. You can change your code behind into codes bellow :
protected void btnAddItem_Click(object sender, EventArgs e) { int i = WebListBox1.SelectedIndex; WebListBoxItem wli = new WebListBoxItem(); wli.Name = WebListBox1.Items[i].Name; wli.Text = WebListBox1.Items.GetNamedItem(wli.Name).Text; WebListBox2.Items.Add(wli); }
Please let me know whether it is work as your expectation or not ?
Hope this helps.Riendy
No that didn't work either
The selectedIndex just isn't being persisted on postback
Hi Neil,
Would you please let me know which one didn't work ? Did you get an error or something ?
Attached is my simple runable sample (WebListBox - SelectedItem). Is it possible for you to take a look at my attachment? Please let me know if it is still not answer you question.
Thank you.Riendy
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname