查找按钮不会在网格中显示所选记录

时间:2013-10-17 18:30:22

标签: c# asp.net

我需要在页面中添加一个文本框,允许用户从网格中查找作者。我的问题是我的用户没有任何操作点击查找作者按钮。没有出现错误。这是页面中的代码:

    <asp:TextBox runat="server" ID="txtAuthors" Text='<%# Bind("AuthorName") %>' />
    <asp:ImageButton runat="server" ID="btn_FindAuthors"  OnClick="btnFindAuthors"/>
    <ajaxToolkit:AutoCompleteExtender ID="fndAuthors" runat="server" DelimiterCharacters="" Enabled="True" ServicePath="~/WebServices/AuthorsWebService.asmx" ServiceMethod="AutoComplete" TargetControlID="txtAuthors" MinimumPrefixLength="3" />             


       <asp:GridView runat="server" ID="gvAuthors" DataSourceID="sqlAuthors" DataKeyNames="AuthorID" AutoGenerateColumns="false">
        <Columns>
            <asp:HyperLinkField HeaderText="Author Name" DataNavigateUrlFormatString="~/Author_Details.aspx?id={0}" DataNavigateUrlFields="AuthorID" DataTextField="AuthorName" />

        </Columns>

      </asp:GridView>

以下是单击“查找作者”按钮时调用的脚本:

protected void btnFindAuthors(Object sender, EventArgs e)
{
       GridViewRow row = gvAuthors.SelectedRow;
}

以下是自动填充代码:

public string[] AutoComplete(string prefixText, int count)
{
    List<AuthorName> authors= AuthorName.GetAuthorList(prefixText);
    return (from aa in authors select aa.AuthorName).ToArray();

这是我的其他代码:

 public string[] GetAuthorList(string prefixText, int count)
    {
         ArrayList arrayList = new ArrayList();
         Products prod = new Products();   

     using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Libros"].ConnectionString))
    {
        conn.Open();

        string sqlQuery = @"SELECT Authorid" +
                        " ,[AuthorLastName] " +
                        " FROM [mdb].[dbo].[Authors] " +
                        " WHERE AuthorName like @AuthorName ";

         using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
        {
            cmd.Parameters.AddWithValue("@AuthorName", prefixText + "%");

            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        arrayList.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(reader["AuthorName"].ToString(), reader["AuthorID"].ToString()));
                    }
                }
                else
                {
                    arrayList.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem     ("There are no authors with that name in our library system.", "-1"));
                }
            }
        }
    }

为什么网格不会显示与从txtAuthor文本框中选择的作者姓名相对应的记录?我该如何解决这个问题?

0 个答案:

没有答案