Nepethya Rana

Nepethya Rana

  • NA
  • 335
  • 151.9k

Need help to work on dropdownlist when pagepostback

Jun 6 2016 8:19 PM
I have created simple webform with two dropdownlists which get loaded with numbers on page load event. I have add, sub, mul, divide buttons to operate calculation and a label to display result.

When i select two numbers from dropdownlist and hit the buttons, I got 0 as result.
 
My Code:
protected void Page_Load(object sender, EventArgs e)
{
MyCalculationClient mc = new MyCalculationClient();
DropDownList1.DataSource = mc.DisplayNumbers();
DropDownList1.DataTextField = "Number";
DropDownList1.DataBind();
DropDownList2.DataSource = mc.DisplayNumbers();
DropDownList2.DataTextField = "Number";
DropDownList2.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(DropDownList1.Text);
int b = Convert.ToInt32(DropDownList2.Text);
MyCalculationClient add = new MyCalculationClient();
Label1.Text = add.Add(a, b).ToString();
}
 

Answers (1)