View Single Post
  #4  
Old 03-13-2008, 03:02 AM
poornima poornima is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 188
poornima is on a distinguished road
Smile Re: Extracting specific elements from listbox

Hi,
Try like this,
It is very similar to DropDownList...
In aspx page,
<div>
<asp :TextBox ID="sampleTextBox" runat="server"></asp:TextBox>
<asp :Button ID="selectButton" runat="server" Text="Select" OnClick="selectButton_Click" />
</div>
<div>
<asp :ListBox ID="sampleListBox" runat="server">
<asp :ListItem Text="Apple" Value="Apple"></asp:ListItem>
<asp :ListItem Text="Banana" Value="Bannana"></asp:ListItem>
<asp :ListItem Text="PineApple" Value="PineApple"></asp:ListItem>
<asp :ListItem Text="Grapes" Value="Grapes"></asp:ListItem>
</asp :ListBox>
</div>
Write this Coding in Button Click Event... in code-behind
protected void selectButton_Click(object sender, EventArgs e)
{
if (sampleTextBox.Text == "1")
sampleListBox.SelectedIndex = 0;
if (sampleTextBox.Text == "2")
sampleListBox.SelectedIndex = 1;
if (sampleTextBox.Text == "3")
sampleListBox.SelectedIndex = 2;
if (sampleTextBox.Text == "4")
sampleListBox.SelectedIndex = 3;
}
So according to the value in textbox the value is selected in ListBox.
This is just a sample coding,try to implement this in your project...
Reply With Quote