0

1) I have a textbox to enter initial letters of the item and, 2) a search button on click of which a listbox appears showing the matching searches. 3) I want to convert this into autocomplete extender and want to remove the listbox. Following is my code which I have tried:

    [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public List<string> OnSearchEntity(string prefixText, int count)
    {
        List<string> outsideEntities = new List<string>();
        DataTable dtOutsideEntity = COIOrganizationCollection.GetOrganizations(prefixText);

        for (int i = 0; i < dtOutsideEntity.Rows.Count; i++)
        {
            outsideEntities.Add(dtOutsideEntity.Rows[i]["Name"].ToString());
        }
        return outsideEntities;
    }

but it is showing an error:

Error 82 No overload for 'OnSearchEntity' matches delegate 'System.Web.UI.ImageClickEventHandler'

I have also tried changing the parameters, viz.

    public List<string> OnSearchEntity(object sender, ImageClickEventArgs e)
    {
        List<string> outsideEntities = new List<string>();
 DataTable dtOutsideEntity =COIOrganizationCollection.GetOrganizations(entityName.Text.Trim());

        for (int i = 0; i < dtOutsideEntity.Rows.Count; i++)
        {
            outsideEntities.Add(dtOutsideEntity.Rows[i]["Name"].ToString());
        }
        return outsideEntities;
    }

it again gives an error: Error 83 'System.Collections.Generic.List has the wrong return type

kindly help, or suggest the right way for this conversion.

2 Answers2

0

Pass List of outsideEntities into the arguments using Lambda expression ,It will get changed automatically once event is fired. No need to return this list . You can use this example and change it for your event

    lnkSynEvent.Click += 
               new EventHandler((s,e)=>lnkSynEvent_Click(s, e, your_parameter));

Be careful same lines may get excecuted manytimes in event , even the event is fired just once

Charlie
  • 4,827
  • 2
  • 31
  • 55
  • this event doesn't have any definition for "click" – user3931799 Sep 09 '14 at 07:02
  • that is just example ..You have to use it as your requirement forexample Image.ImageClick+=new ImageClickEventHandler((s,e)=>OnSearchEntity(s,e,outsideEntities) – Charlie Sep 09 '14 at 07:06
0

the error was because : i had used image button on click event, and for the same function i was using it for two different type of parameters,viz.

onsearch(sender, eventargs e), and onsearch(string a, int count)

in my case i could remove the button since i was converting it to autocomplete extender so search button was not required.

thank you for the help!