How can I write an event that does a specified calculation when an option is selected that the submit button is selected? Say I have the following code:

<form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>Go swimming</asp:ListItem>
            <asp:ListItem>Play sudoku</asp:ListItem>
            <asp:ListItem>Practice piano</asp:ListItem>
            <asp:ListItem>Play solitaire</asp:ListItem>
        </asp:DropDownList>
       <br />
       <br />
        <asp:Button ID="Train" runat="server" Text="Train" onclick="Train_Click" /><br /><br />
        <asp:Label
            ID="testLabel" runat="server" />
    </div>
    </form>

I have four options: go swimming, play sudoku, practice piano, and play solitaire. I have a button, and a label to display the value of the calculation performed for testing purposes. Say I want to set an event that says:

If go swimming is selected, multiply 500 by .001, and display this value in the label, when the button is pressed.

If play sudoku is selected, multiply 500 by .002, and display this value in the label, when the button is pressed.

etc...

How would I go about starting this event out?

Recommended Answers

All 3 Replies

in button clcik event you can get the dropdown seleclted value and write the code according to your requirement?let me know if u face any problem?

in button clcik event you can get the dropdown seleclted value and write the code according to your requirement?let me know if u face any problem?

Can you help me with how to get the value of the drop down option? I do not know how to do that. I know how to get values of textboxes. I am also unsure of how to write the calculation in asp.net. I have learned how to write a similar calculation in Javascript, but I know asp.net is going to be different. Can you help?

The logic will be same irrespective of languages!.the sample code will be like

//in button click event
int index=Convert.ToInt32(DropDownList1.SelectedIndex);
if(index=0)//swim
{
Label1.text=(500*0.001).ToString();
}
else if(index==2)
{
//something
}
else 
{//something
}

i have written code here only.make sure that proper case while writing code as c#is case sensitive...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.