ASP.Net Int32.Parse Error: input string was not in a correct format

akhter
 
on Jun 29, 2020 11:28 PM
1182 Views

How to pass null value in label

i am trying to pass null value from 

int lbpk = Int32.Parse(lbitpqty.Text);

but it is giving error input string was not in a correct format

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jun 30, 2020 01:07 AM
akhter says:
int lbpk = Int32.Parse(lbitpqty.Text);

lbitpqty.Text value is empty. So you are getting the error.

You need to check when lbitpqty.Text is empty then set the lbpk to zero.

Use below code.

int lbpk = !string.IsNullOrEmpty(lbitpqty.Text) ? Int32.Parse(lbitpqty.Text) : 0;