I have a textbox in my asp page and yes I using database.
I want to show all names which is all names previously entered. When a user types in a letter in that textbox, whatever names starting with that letter.
the names are from a list generated by other function, pulled out from active directory.
So for example:
When user types in "a" in a textbox then automactically names "aron" "asron" "amanda" in the list shows, and user can select one of those names.
Actually I'm using ASP language not ASP.NET. I have tried using normal coding but I can't get the result that I want bacause if I using that coding, user must entered full name instead the first letter.
1
Expert's answer
2011-08-23T14:11:06-0400
There are two ways we can use Autocomplete feature 1. Auto complete textBox with previously entered text in textbox. 2. AutoComplete textBox by fetching the data from database.
1. Auto complete textBox with previously entered text in textbox. For filling textbox with previously entered data/text in textbox using Autocomplete feature we can implement by setting autocomplete mode proeprty of textbox to suggest, append or sugestappend and setting autocomplete source to custom source progrmetically First of all create a global AutoCompleteStringCollection and write code like this namespace WindowsApplication1 { public partial class Form1 : Form { AutoCompleteStringCollection autoComplete = new AutoCompleteStringCollection(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { autoComplete.Add(textBox1.Text); MessageBox.Show("hello"); }
2. AutoComplete textBox by fetching the data from database.
For this i've created a database with a table containing names which will be shown in textbox as suggestions, for this we need to create a AutoCompleteStringCollection and then add the records in this collection using datareader to fetch records from database
For autocomplete functionalty to work we need to define these 3 properties of textbox
1. AutoCompleteMode - we can choose either suggest or appned or suggestappend as names are self explanatory
2. AutoCompleteSource - this needs to be set as Custom Source
3. AutoCompleteCustomSource - this is the collection we created earlier
The complete C# code will look like this
namespace AutoCompleteTextBox {
public partial class frmAuto : Form { public string strConnection = ConfigurationManager.AppSettings["ConnString"]; AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection(); public frmAuto() { InitializeComponent(); }
private void frmAuto_Load(object sender, EventArgs e) { SqlDataReader dReader; SqlConnection conn = new SqlConnection(); conn.ConnectionString = strConnection; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.CommandText = "Select distinct [Name] from [Names]" + " order by [Name] asc"; conn.Open(); dReader = cmd.ExecuteReader(); if (dReader.HasRows == true) { while (dReader.Read()) namesCollection.Add(dReader["Name"].ToString());
} else { MessageBox.Show("Data not found"); } dReader.Close();
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment