Click here to Skip to main content
15,903,724 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Can I bind textbox like dropdownlist means in dropdownlist we can set datatextfield to show text and datavaluefield to insert value into database.

I have to do using textbox,I have added Autocomplete ajax toolkit extender to textbox. I am showing only Student Names but on click of button i have to insert SID of student not student name into the database.I search google they tell me use OnClientItemSelected of Autocomplete extender.How can i do any idea regarding this.


C#
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
        public static string[] Getdata(string prefixText, int count, string contextKey)
        {
            strSQL = "SELECT SID,Student_Name FROM Student_Master WHERE Student_Name Like '" + prefixText + "%'";
            DataTable dataTablePatient_Master = null;
            dataTablePatient_Master = objSqlDbComm.ExecuteDatasetQuery(strSQL).Tables[0];

            List<String> list = new List<String>();
            foreach(DataRow dr in dataTablePatient_Master.Rows)
            {
                list.Add(dr["Student_Name"].ToString());

            }
            return list.ToArray();
        }


ASP.NET
<asp:TextBox ID="txtStudentName" AutoCompleteType="Disabled" CssClass="csstextbox"
                                    runat="server"></asp:TextBox>
                                <asp:AutoCompleteExtender ID="txtStudentName_AutoCompleteExtender" runat="server"
                                    ServiceMethod="Getdata" OnClientItemSelected="OnItemSelected" CompletionListCssClass="cssautocompletetextbox" MinimumPrefixLength="1"
                                    CompletionInterval="1000" EnableCaching="true" CompletionSetCount="1" TargetControlID="txtStudentName"
                                    UseContextKey="True">
                                </asp:AutoCompleteExtender>
Posted
Updated 28-Jun-12 20:13pm
v2

try the running project for your requirement

Using the AutoComplete Extender to Automatically Perform a PostBack[^]

mark solution if you get your answer.


Thanks
ashish
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900