I need to select the value of dropdownlist and put it on textbox I tried theses but not working
$('#<%= DDL_ID.ClientID %>').change(function() { $('#<%= TextBoxID.ClientID %>').val($(this).val()); }); protected void DDL_SelectedIndexChanged(object sender, EventArgs e) { var selectedValue = ((DropDownList)sender).SelectedValue; TextBox1.Text = selectedValue; }
Praveen SreeramPosted Jul 4, 2016, 1:17 AM
- Are you having both the codes that you have mentioned in your page?
- is the AutoPostBack property of the dropdown is set to true?
If your answer is yes for both of my Questions above, then the client side script will not work.Posted Jul 4, 2016, 6:09 AM
DataTextField="VideoName" DataValueField="MaId" AutoPostBack="true" Width="130px" Height="25px" AppendDataBoundItems="true" OnSelectedIndexChanged="selectForTextBox">
*
runat="server" ValidationGroup="click2" InitialValue="Select Lecture" SetFocusOnError="true" />
SelectCommand="SELECT [MaId], [VideoName] FROM [Material] ">
Code behind
protected void selectForTextBox(object sender, EventArgs e)
{
var selectvalue = ((DropDownList)sender).SelectedValue;
TextBox1.Text = selectvalue;
}
Also I tried this javascript code
function select() {
var textbox = document.getElementById('<%=TextBox1.ClientID%>');
var parLab = document.getElementById('<%=DropDownList1.ClientID%>').option[document.getElementById('<%=DropDownList1.ClientID%>').selectedIndex].text;
if (parlab != 'Select Lecture') {
textbox.value = parlab;
} else {
textbox.value = '';
}
}
Dharmesh SinghPosted Jul 3, 2016, 11:35 PM