Click here to Skip to main content
15,889,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
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.
Posted

XML
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="SelectedIndexChanged">
            <asp:ListItem Value="Value 1" Text="Value 1" />
            <asp:ListItem Value="Value 2" Text="Value 2" />
            <asp:ListItem Value="Value 3" Text="Value 3" />
            <asp:ListItem Value="Value 4" Text="Value 4" />
            <asp:ListItem Value="Other" Text="Other" />
        </asp:DropDownList>


        <asp:TextBox ID="TextBox1" runat="server" />
    </div>
    </form>
</body>


C#
public void SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList dropDownList = (DropDownList)sender;
            if (dropDownList.SelectedValue == "Other")
            {
                TextBox1.Enabled = true;
                TextBox1.Text = string.Empty;
            }
            else
            {
                TextBox1.Enabled = false;
                TextBox1.Text = dropDownList.SelectedValue;
            }
        }
 
Share this answer
 
Comments
Aviinash 31-Oct-15 7:40am    
I need textbox like dropdownlist like i should have textbox value and textbox text so that i can get the id of student using textbox onselectedtext change and then send that id to database to bind other thing
Hello ,
Good Day!!!

Editable Drop-down list may help you for your requirement
better you try this one .............

Custom ASP.NET Editable DropDownList[^]
 
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