且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果在c#中其单元格包含0值时,如何将一些文本设置为datagridview单元格

更新时间:2023-02-04 20:12:18

然后你可以直接从数据库中获取NULL值是SQL语句

then you can directly get the NULL value from database is SQL Statement
CASE WHEN YOURCOLUMN=0 THEN NULL ELSE YOURCOLUMN END





i我不确定哪个列显示0表示前检查第一个co lumn





i am not sure which column is showing 0 for ex check the first column

select CASE WHEN l.admission_number=0 THEN NULL ELSE l.admission_number END ADMISSION_NUMBER,l.student_class ,l.student_name,hindi,maths,social,l.telugu,l.english ,
'' as english_1,'' as english_2,l.science, '' as ns,'' as ps  
from lkg_to_seventh_marks as l
union all 
select e.admission_number ,e.student_class ,
e.student_name ,hindi,maths,social,e.telugu,'' as english,e.english_1 ,e.english_2,'' as science,e.ns,e.ps 
from eighth_to_ninth_marks as e


<itemtemplate>
 <asp:label id="lblStatus" runat="server" text="<%# SetZeroToNull(Eval("value").ToString()) %>" xmlns:asp="#unknown" />
</itemtemplate>





现在在代码后面编写SetZeroToNull()方法就好了。




now write SetZeroToNull() method in code behind like.

private string SetZeroToNull(string value)
{
    if (value == "0")
    {
        return null;
    }
    else
    {
        return value;
    }
}







或者你可以写任何你想要的东西




or you can write any thing you want