Link to home
Start Free TrialLog in
Avatar of ernie_shah
ernie_shahFlag for Trinidad and Tobago

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.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
Avatar of rajeeshmca
rajeeshmca
Flag of India image

Hi,

Could you please post the aspx page as well

Also check with the spelling and Case sensitiveness (Capital and small letters)

Regards
Rajeesh
Avatar of ernie_shah

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>

Open in new window


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

Open in new window



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
Avatar of Naman Goel
Naman Goel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Open in new window

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.