0

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?

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by srikanthkadem
0

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?

0

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?

0

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...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.