weixin_33716154 2010-10-05 13:18 采纳率: 0%
浏览 18

AutoCompleteExtender问题

I'm using an AutoCompleteExtender for an ASP.NET project of mine, and it's pulling the fields to be shown fine. However, when the user chooses an autocomplete suggestion, I need the function to pull another field from the row (the 'ID' column which is the primary key), as that what is the necessary field used to display the relevant data.

Here is my code

public string[] GetAutoComplete(string prefixText)
        {
            int count = 10;
            string sql = "SELECT * FROM SageAccount WHERE Name LIKE @prefixText";
            SqlDataAdapter da = new SqlDataAdapter(sql, "My Connection String(changed due to personal info being shown)");
            da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
            DataTable dt = new DataTable();
            da.Fill(dt);
            string[] items = new string[dt.Rows.Count];
            int i = 0;
            foreach (DataRow dr in dt.Rows)
            {
                items.SetValue(dr["Name"].ToString(), i);
                i++;
            }
            return items;
        }

EDIT: Some modified code I am trying:

public string[] GetAutoComplete(string prefixText, int count)
{
    string sql = "SELECT * FROM SageAccount WHERE Name LIKE @prefixText";
    SqlDataAdapter da = new SqlDataAdapter(sql, "Con string");
    da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
    DataTable dt = new DataTable();
    da.Fill(dt);
    List<string> Names = new List<string>();
    //string[] items = new string[dt.Rows.Count];
    int i = 0;
    foreach (DataRow dr in dt.Rows)
    {
            Names.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["Name"], dr["ID"].ToString());
        //items.SetValue(dr["Name"].ToString(), i);
    }
    return Names.ToArray();

The issue I have here is that it gives me the error:

The best overloaded method match for 'AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItems(string, string)' has some invalid arguements'

Any ideas? Many thanks

  • 写回答

1条回答 默认 最新

  • weixin_33698823 2010-10-05 13:33
    关注

    I've done that in the past using a hidden field to save the selected id. Check out HERE or go over google and check how to use a hidden field, I don't have the code right now.

    EDIT 2: Check out that you are expecting an int parameter on your new method, and you are calling sending an string. and .. check that you are calling another method called CreateAutoCompleteItems which it seems to be missings

    评论

报告相同问题?

悬赏问题

  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误