how to show blank instead of 0 in datagridview c#.net -


i working on window application visual studio 2010 , sql server 2008. code working fine. need 1 thing if value 0.000 in database, should shown blank in datagridview. please, give me solution. in advance. code given below:

sda = new sqldataadapter("select item, cast (val1 decimal (10,3)), cast (val2 decimal (10,2)), cast (val3 decimal (10,2)), cast (val4 decimal (10,3)), sno opstk vno ='" + txtvno.text + "'",  con);         datatable dt = new datatable();         sdaq.fill(dt);          datagridview1.rows.clear();         foreach (datarow item in dt.rows)         {             int n = datagridview1.rows.add();             datagridview1.rows[n].cells[0].value = item["item"].tostring();             datagridview1.rows[n].cells[1].value = item[1].tostring();             datagridview1.rows[n].cells[2].value = item[2].tostring();             datagridview1.rows[n].cells[3].value = item[3].tostring();             datagridview1.rows[n].cells[4].value = item[4].tostring();             datagridview1.rows[n].cells[5].value = item[5].tostring();          } 

you can try this:
double value = convert.todouble(item["item"]); datagridview1.rows[n].cells[0].value = value == 0 ? "" : value.tostring(); dirty, should call datagridview1.datasource = yourdatatable;


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -