AutoComplete与RadioButtonList1配合使用遇到的问题,在线等
我用的是vs2008的AutoComplete控件,如果单独与TextBox控件使用,是没有问题的,代码如下:
 public static string[] GetCompletionList(string prefixText, int count, string contextKey)
        {
            SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand cmd = new SqlCommand("SELECT cp_name FROM chanpin WHERE cp_name like '%" + prefixText + "%' ORDER BY cp_id DESC", cn);
            cn.Open();


}
====================
但我想和RadioButtonList1配合使用,即代码如下:
public string[] GetCompletionList(string prefixText, int count, string contextKey)
        {
            string abc = "";
            SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
            if (RadioButtonList1.SelectedItem.Text == "公司")
            {
                abc = "select g_name from gscx where g_name like '%" + prefixText + "%' order by g_id desc";
            }
            else if (RadioButtonList1.SelectedItem.Text == "产品")
            {
                abc = "select cp_name from chanpin where cp_name like '%" + prefixText + "%' order by cp_id desc";
            }

。。
}
以上代码没有反应,即得不出自动完成效果,也没有任何错误提示,望高手解答。

解决方案 »

  1.   

    你调试下看是否执行了你的代码

    你改用selectedvalue,试下
    RadioButtonList1.SelectedValue 
      

  2.   

    public static string[] GetCompletionList

    public string[] GetCompletionList
    的区别啊?
    我用static ,RadioButtonList1就提示出错
      

  3.   

    这样好像行不通啊。要不你用session或者cookie存下选中的那个RadioButtonList1的值,然后到web服务的后台GetCompletionList方法里获取session或者cookie的值。呵呵,只能这样了
      

  4.   

    =============
    这个方法,RadioButtonList1的值,怎么存,没搞懂。
      

  5.   

    简单啊,你在后台把RadioButtonList1.SelectedItem.Text存cookie里面,然后给RadioButtonList1弄个服务器的selectedchange事件,里面也存RadioButtonList1.SelectedItem.Text;
      

  6.   

    这个办法就很好啊,因为你那是web服务,除非你改那个控件,添加个属性过去