ernie_shah
asked on
Assign value to textbox from dropdown list
I am trying to assign values to three text boxes based on the selected value of a drop down box when a button is clicked.
I am new to asp.net.
Can anyone tell me what is wrong with my code as nothing happens when i click the button?
Protected Sub btnPreview_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPreview.Click
If ddlMonth.SelectedItem.valu e = "January" Then
CycleNo1.Text = 1
CycleNo2.Text = 1
CycleNo3.Text = CycleNo1.Text + 1
ElseIf ddlMonth.SelectedItem.valu e = "February" Then
CycleNo1.Text = 2
CycleNo2.Text = 2
CycleNo3.Text = CycleNo1.Text + 1
ElseIf ddlMonth.SelectedItem.Valu e = "March" Then
CycleNo1.Text = 3
CycleNo2.Text = 3
CycleNo3.Text = CycleNo1.Text + 1
End If
End Sub
I am new to asp.net.
Can anyone tell me what is wrong with my code as nothing happens when i click the button?
Protected Sub btnPreview_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPreview.Click
If ddlMonth.SelectedItem.valu
CycleNo1.Text = 1
CycleNo2.Text = 1
CycleNo3.Text = CycleNo1.Text + 1
ElseIf ddlMonth.SelectedItem.valu
CycleNo1.Text = 2
CycleNo2.Text = 2
CycleNo3.Text = CycleNo1.Text + 1
ElseIf ddlMonth.SelectedItem.Valu
CycleNo1.Text = 3
CycleNo2.Text = 3
CycleNo3.Text = CycleNo1.Text + 1
End If
End Sub
ASKER
I am away from my office for the week but will post on Monday. Please look forward. So grateful for the assistance.
<form id="form1" runat="server">
<div>
<asp:dropdownlist ID="ddlMonth" runat="server" AutoPostBack ="true" >
<asp:ListItem Text="January" Value ="January"></asp:ListItem>
<asp:ListItem Text="February" Value ="Feburary"></asp:ListItem>
<asp:ListItem Text="March" Value ="March"></asp:ListItem>
</asp:dropdownlist>
<asp:TextBox ID="CycleNo1" runat="server"></asp:TextBox>
<asp:TextBox ID="CycleNo2"
runat="server"></asp:TextBox>
<asp:TextBox ID="CycleNo3" runat="server"></asp:TextBox>
<asp:Button ID="btnPreview" runat="server" Text="Button" />
</div>
</form>
Protected Sub btnPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPreview.Click
If ddlMonth.SelectedItem.Value = "January" Then
CycleNo1.Text = 1
CycleNo2.Text = 1
CycleNo3.Text = CycleNo1.Text + 1
ElseIf ddlMonth.SelectedItem.Value = "February" Then
CycleNo1.Text = 2
CycleNo2.Text = 2
CycleNo3.Text = CycleNo1.Text + 1
ElseIf ddlMonth.SelectedItem.Value = "March" Then
CycleNo1.Text = 3
CycleNo2.Text = 3
CycleNo3.Text = CycleNo1.Text + 1
End If
End Sub
Place button click code by double clicking the button in design mode or Select the events of click from Cod behind file for button "btnPreview"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
adding designer code :
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Partial Public Class _Default
'''<summary>
'''form1 control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents form1 As Global.System.Web.UI.HtmlControls.HtmlForm
'''<summary>
'''ddlMonth control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents ddlMonth As Global.System.Web.UI.WebControls.DropDownList
'''<summary>
'''CycleNo1 control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents CycleNo1 As Global.System.Web.UI.WebControls.TextBox
'''<summary>
'''CycleNo2 control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents CycleNo2 As Global.System.Web.UI.WebControls.TextBox
'''<summary>
'''CycleNo3 control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents CycleNo3 As Global.System.Web.UI.WebControls.TextBox
'''<summary>
'''btnPreview control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents btnPreview As Global.System.Web.UI.WebControls.Button
End Class
ASKER
Good Morning:
Great thanks.
I also realize my combobox that is extracting data from the database has its value to the primary key which is numeric (2 rather than February) and all works fine now.
Much appreciated.
Great thanks.
I also realize my combobox that is extracting data from the database has its value to the primary key which is numeric (2 rather than February) and all works fine now.
Much appreciated.
Could you please post the aspx page as well
Also check with the spelling and Case sensitiveness (Capital and small letters)
Regards
Rajeesh