1

The case is like this: The db table like this: db

And The desired UI is Like this: UI

Is this possible to do? I want to make autocomplete, up to full name, then, when user enter, example, john, so, all customers who have name with john will be shown with branch name additional data, and if user select one of the rows at popup, it will update cif number. Example: -John Doe | Mighigan branch -John Alex | Cairo branch -David John | Canada Branch

So far, I search popup autocomplete at asp.net it just lookup one column, at database, and update same textfield. I need it to update more than one textfield, Customer name and cif number. Or, just CIF number but the autocomplete will lookup customer name and branch name.

Thank you very much.

Khaneddy2013
  • 1,301
  • 1
  • 17
  • 25
  • Yes you can do that ? Join your two columns `fullname` and `branch name` and use that to bind the `autocomplete ` then when user selects update all other fields on UI. – Mahesh Jan 30 '15 at 05:49
  • Is there tutorial which discussing same case, Sir? – Khaneddy2013 Jan 30 '15 at 06:05
  • First of all I am no sir and I am not sure if there is tutorial, but you can start working on it and come here in case of issues. – Mahesh Jan 30 '15 at 06:08
  • I think for displaying CIF - Name - Branch format is easy. I can use this: http://www.aspdotnet-suresh.com/2011/05/ajax-autocompleteextender-sample.html but, how if I choose one of results, and update Customer cif textfield? There is no event after selection... – Khaneddy2013 Jan 30 '15 at 06:18
  • I thought you are using `jquery` autocomplete as you tagged it with the `Jquery` but if you are using the ajaxtoolkits control then try to force textchange event on textbox after selection. – Mahesh Jan 30 '15 at 06:30

1 Answers1

0

For forcing the text selected event you can subscribe on TextChanged event and use function below as handler for itemSelected extender's client event OnClientItemSelected="autoCompleteEx_ItemSelected":

<script type="text/javascript">
 function autoCompleteEx_ItemSelected(sender, args) {
      __doPostBack(sender.get_element().name, "");
 }
</script>

And you may want to remove AutoPostBack="true" from a target textbox

And your postback event will be

 protected void autoCompleteTextbox_ValueChanged(object sender, EventArgs e)
  {
    ///populate the form based on retrieved data
  } 

From this link you need to join your two fields as

    List<string> autocompleteList= new List<string>();
    for (int i = 0; i < dt.Rows.Count; i++)
    {
      autocompleteList.Add(dt.Rows[i]["FullName"].ToString()+"|"+dt.Rows[i]["BranchName"].ToString());
    }

Put your OnClientItemSelected="autoCompleteEx_ItemSelected" in automcomplete extender.

  <ajaxtoolkit:AutoCompleteExtender runat="server" 
    //other properties 
    OnClientItemSelected="autoCompleteEx_ItemSelected">
</ajaxtoolkit:autocompleteextender>
Mahesh
  • 8,694
  • 2
  • 32
  • 53
  • where should I put OnClientItemSelected? at tag? I know how to use jquery, but, If there is tool easier to use, I want use it. jQuery tag is not easily readable at ms visual studio. visual studio can not detect typo at jQuery syntax. – Khaneddy2013 Jan 30 '15 at 06:50
  • __doPostBack(sender.get_element().name, ""); is that means I should create __doPostBack function? If yes, at the client side or server side? – Khaneddy2013 Jan 30 '15 at 07:12
  • `__doPostBack()` is used by asp to fire the `postback` events by generating the javascript code. We are using the same function to force the postback on the page for that post back we need to write the event in code behind. Like i have mentioned in the answer. So here `__doPostBack(sender.get_element().name, "");` will call the event on page behind which matches the `sender.get_element().name` so if this value is `autoText` then code behind event would be `protected void autoText_ValueChanged(object sender, EventArgs e)` – Mahesh Jan 30 '15 at 07:16
  • [Read this for more info](http://stackoverflow.com/questions/3591634/how-to-use-dopostback) – Mahesh Jan 30 '15 at 07:16
  • Excuse me, at that sample code is using web service. I am not using web service. Is that possible to use common code behind? Is there good example using code behind and will get string value on textbox? – Khaneddy2013 Feb 04 '15 at 03:38
  • What do you mean code behind to get string value on textbox? – Mahesh Feb 04 '15 at 05:13
  • maybe like this: protected void btnSave_Click(object sender, EventArgs e) {} that case is btnSave OnClick Event. so, at aspx at the component maybe On(NameOfEvent)_(EventName) the at aspx.cs will exist code like that – Khaneddy2013 Feb 04 '15 at 05:56
  • Same is this code is doing you want to populate your data on selection of the dropdown right ? so if you see last code snippet the ` OnClientItemSelected="autoCompleteEx_ItemSelected">` this will force the ajaxtoolkit to fire the postback for `protected void autoCompleteTextbox_ValueChanged(object sender, EventArgs e)` this event and in that event you can populate your form data – Mahesh Feb 04 '15 at 06:00