我有以下代碼,我試圖通過幾條if
語句,但我在將標籤的內容設置爲0
時出現問題;無法將標籤的內容設置爲零
private void UnderRunBumper()
{
lblGVMAmount.Content = 0; //Issue here
if (Convert.ToInt32(txtExternalLength.Text) >= 6000)
lblUnderRunBumper.Content = "Under-Run Bumper";
else if (Convert.ToInt32(lblGVMAmount.Content.ToString()) >= 8000)
lblUnderRunBumper.Content = "Under-Run Bumper";
else if (cmbBodyType.SelectedIndex == 6 || cmbBodyType.SelectedIndex == 7 || cmbBodyType.SelectedIndex == 8 || cmbBodyType.SelectedIndex == 9 || cmbBodyType.SelectedIndex == 10)
lblUnderRunBumper.Content = "Under-Run Bumper";
else lblUnderRunBumper.Content = "";
}
我得到的錯誤:
Object reference not set to an instance of an object.
我不明白。爲什麼我不能將標籤的值設置爲0?
你爲什麼要發佈[6小時相同質詢時(http://stackoverflow.com/questions/36337084/setting-label-content-causes-issues) – MethodMan
是lblGVMAmount空當您嘗試將其內容屬性設置爲0? –
@ MADsc13nce是的,它是:) – CareTaker22