c# - How to select a value from CSV in an asp.net ajax toolbox autocomplete and pass that value to other textbox? -


i have used ajax toolkit autocomplete working fine using following asp.net , c# code.

 <asp:updatepanel id="updpnlmedicinename" runat="server" >   <contenttemplate>            name<br />                <asp:textbox id="txtmedname" runat="server" width="150px"                     ontextchanged="txtmedname_textchanged"></textbox>   <cc1:autocompleteextender id="txtsearchid_autocompleteextender" runat="server"    delimitercharacters="" onclientitemselected="itemselected" enabled="true" getmedicine" servicepath="search/namesearch.asmx" targetcontrolid="txtmedname" minimumprefixlength="1">  </cc1:autocompleteextender> 

my code behind :

[webmethod] public string[] getmedicine(string prefixtext) {  list<string> liststring = new list<string>();  using (sqlconnection con = new  sqlconnection(configurationmanager.connectionstrings["newlandconnectionstring"].connectionstring)) {  sqlcommand com = new sqlcommand("select productname+','+productcode+',' + (select unitname unit unit.id=product1.unitid) productdetails,productid product1 productname '"+prefixtext+"%'", con);  con.open();  sqldataadapter adr = new sqldataadapter(com);  datatable dt = new datatable();  adr.fill(dt);   (int j = 0; j < dt.rows.count; j++)         {             string countproduct = dt.rows[j]["productdetails"].tostring();             liststring.add(autocompleteextender.createautocompleteitem(dt.rows[j]["productdetails"].tostring(),dt.rows[j]["productid"].tostring()));         }   }     string[] strarray = liststring.toarray();     return strarray;  } 

now when auto complete works values in form of : somename,code,unit want if value selected must first value csv i.e "somename" in texbox , other 2 values(i.e code,unit ) must populated in other texboxes respectively.

please, me in achieving task.

thanks in advance !!

finally, got solution myself , of link , hope also.so, i'm providing code below above query:

onclientitemselected on autocompleteextender control run javascript function   <script type="text/javascript">     function itemselected(sender, args) {         __dopostback(sender.get_element().name, "");     } </script> 

now on text change of textbox(autoextender) :

 put below code on textchange event      string obj = txtmedname.text.tostring();//in texbox getting                    //values autoextender , store value in string     string[] namelist = obj.split(','); //finally using split separate csv                                      //values , store in array                                      // getting on autoextender     txtmedname.text = namelist[0].tostring();//now pass values respective                                               //texboxes     txtbox2.text = namelist[1].tostring();     txtbox3.text = namelist[2].tostring(); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -