Use the
ToString
method with required format as shown below:
txtDept.Text = emp.DepID.ToString();
txtSalary.Text = emp.salary.ToString("N2");
The question was not clear. If it is required to convert the
string
representation of the number to its native value then there are several approaches. One option is to use
Convert.ToInt32, Convert.ToDecimal
etc. methods as these will not
throw exception
even when the input value is
null
as shown below:
emp.DepID=Convert.ToInt32(txtDept.Text);
emp.salary=Convert.ToDecimal(txtSalary.Text);