我有一個從sql數據庫datagridview和它的數據。如何將一些文本設置爲datagridview單元格,當它的單元格在c#中包含0值時?
我的datagridview一些單元格填充0(零)值。
我想在datagridview中填充0值的位置設置NULL文本。
//I'm using this code but not working
private void dataGridView4_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
for (int i = 0; i < dataGridView4.Rows.Count; i++)
{
for (int j = 7; j < dataGridView4.Rows[i].Cells.Count; j++)
{
if (Convert.ToInt32(dataGridView4.Rows[i].Cells[j].Value) == 0)
{
dataGridView4.Rows[i].Cells[j].Value = "Null";
}
}
}
}
我的SQL查詢:
select l.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
我想你不能手動操作字段,因爲你是數據綁定。 – RadioSpace 2014-10-28 06:28:19
通過什麼方式獲得「數據」,即數據集/ SQLserver,EF/MySQL,EF/SQLserver? – RadioSpace 2014-10-28 06:29:53
是啊..當然我綁定的數據,但我想設置一些文本在0值..如果有任何可能性告訴我PLZ.Here我綁定數據從Microsoft SQL服務器 – 2014-10-28 06:31:25