本文介绍了如何在ASP.Net中创建自动完成组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 我一直在谷歌搜索找到如何在asp.net项目中创建自动完成组合框的最佳方法。但我找不到一个我能理解的答案。 情况是我有一个类别列表,用户必须使用下拉列表来选择类别。由于类别列表太长,我正在考虑使用自动完成组合框,这意味着用户可以向下滚动以选择类别或只是从下拉列表中搜索。请帮助我....我需要一个完整的教程如何使用此方法。解决方案 你可以使用jquery UI 查看这个链接 浏览此链接。使用Ajax你可以解决你的问题。 使用ajax和c#在asp.net中自动完成文本框 [ ^ ] 拿一个文本框,转到它的属性,在那里你会看到autocompletesource将它设置为自定义。并且autocompletemode设置为建议&追加。 现在代码背后: private void Form1_Load( object sender,EventArgs e) { AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection(); SqlDataReader dReader; SqlConnection conn = new SqlConnection(); conn.ConnectionString = strConnection; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.CommandText = 选择不同的[名称]来自[姓名] + 按[名称] asc排序 ; conn.Open(); dReader = cmd.ExecuteReader(); if (dReader.HasRows == true ) { while (dReader.Read()) namesCollection.Add(dReader [ Name]的ToString()); } else { MessageBox.Show( 未找到数据); } dReader.Close(); txtName.AutoCompleteCustomSource = namesCollection; } } hi everyone,i''ve been googling all days to find the best way of how to create the autocomplete combobox in asp.net project.but i cant find an answer that i can understand.the situation is I have a category list that user have to use dropdownlist to select the category.since the list of category is too long,i''m thinking of using autocomplete combobox which means user can either scroll down to choose the category or just search from the drop down list.help me please .... i need a complete tutorial of how to use this method. 解决方案 you can use jquery UIcheck this link Go through this link. Using Ajax you can solve your problem.Auto complete Textbox in asp.net using ajax and c#[^]Take a textbox , goto its property, there you will see "autocompletesource" set it to custom. and "autocompletemode set as Suggest&append.now in code behind:private void Form1_Load(object sender, EventArgs e){ AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection(); 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();txtName.AutoCompleteCustomSource = namesCollection;}} 这篇关于如何在ASP.Net中创建自动完成组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-12 03:54