how do i search from a combo box

c01dud

Member
Joined
Jul 9, 2003
Messages
10
I have used a text box and a button from where i can search for an item from a combo box but i cannot get it to work can anyone please help!!
 
Im assuming youre using the DropdownList web control (and not the ComboBox class of WinForms since you posted in the ASP.NET forum). You can use the FindByText method.

DDL.SelectedIndex = DDL.Items.IndexOf(DDL.Items.FindByText("YourSearchText"))
 
yes thank you

thank you for the prompt reply but what do i need exactly is how do i go about it if i have a text box to type in the searching item then a button to start the search and the combo box itself where the search will be displayed
 
slowly:

you have a DropDowList (WebControl)?
In this DropDownList are Items, like "Item 1", "Item 2" etc...

on your site is a textbox and a button (and the DropDownList).
writing in the textbox "Item 2" and press the button, "Item 2" should be selected in the DropDownList?

Is that what you want to do?
 
yes thats it

Exactly yes!!! so when you enter "item 2"in the text box and then press the button the combo box displays item 2(hopefully)
 
Solution:

Code:
private void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
			{
				DropDownList1.Items.Add("Item 1");
				DropDownList1.Items.Add("Item 2");
				DropDownList1.Items.Add("Item 3");
				DropDownList1.Items.Add("Item 4");
			}
		}


private void Button1_Click(object sender, System.EventArgs e)
		{
			DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(TextBox1.Text));
		}
 
i am very sorry about this

am sorry about this but this the error i get

BC30205: End of statement expected. the error is on this line

private void Page_Load(object sender, System.EventArgs e)

..............
Where do i put the code you have provided so kindly!!!
i am new to ASP.net so i dont really know how to put it together

once again am sorry to bother you like this.
 
OK, my last statement for this topic:

Create new WebProjekt names WebApplication1

The WebForm1.aspx contains following:
Code:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>WebForm1</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<P>
				<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
				<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
			<P>
				<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList></P>
		</form>
	</body>
</HTML>

The WebForm1.aspx.cs contains:

Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
	/// <summary>
	/// Zusammenfassung f
 
This here is ASP.net Forum!!!!!

Try this (javascript):

Code:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>WebForm1</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	<script language="javascript">
		function setDropDownList()
		{
			for (i=0; i<document.forms[0].myDropDownList.children.length; i++)
			{
				if (document.forms[0].myDropDownList.children[i].innerText == document.forms[0].tbToSearch.value)
				{
					document.forms[0].myDropDownList.selectedIndex = i;
					break;
				}
			}
		}
	</script>
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<P><INPUT id="tbToSearch" type="text"><INPUT type="button" value="Button" onclick="setDropDownList();"></P>
			<P><SELECT id="myDropDownList">
				<OPTION selected>Item 1</OPTION>
				<OPTION selected>Item 2</OPTION>
				<OPTION selected>Item 3</OPTION>
				<OPTION selected>Item 4</OPTION>
				<OPTION selected>Item 5</OPTION>
				</SELECT>
			</P>
		</form>
	</body>
</HTML>
 
Just one more thing !!!!

I still dont understand what to do here as all i get are errors on errors . i have included the aspx file which i need to create alongside the databse it is connected to (.mdb)

What the problem is i have to do a small project for a company called graphs on graphs this company has a I.T department. The I.T department holds a load of software packages like office and project (microsoft) etc... they have so many different types of these software packages that whenever they need to install software to networked computers they need to root through a whole shelf of cds to find the particular software.

What i am required to do is that i have to make a web page which holds the names and serial keys for these cds. All the cds are numbered from 1-500 so the webpage has to hold the name, serial keys and also the shelf reference i.e 1-500. The manager also would like me to put a search text box so that the software packages could be found from a combo box specifically. The combo box is where all the software package names are held.

the file is zipped as the i cannot attach mdb and aspx files on this forum

plzzzzzz help !!!!!!
 

Attachments

AM very sorry for you who dowloaded the file that did not exist!!!

Am sorry but whoever downloaded the .aspx file and saw that there was nothing to view here it is agin but this time i have made sure that it works the requirements of the filesare in hte previous posted thread(reply).

raf
 

Attachments

Back
Top