Мне было интересно, есть ли способ покрасить все пустые ячейки в GridView оранжевым цветом. Столбцы в моем GridView динамически генерируются. Любая помощь приветствуется.Цвет всех пустых ячеек в ASP.NET GridView
Спасибо!
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//check if the rowtype is a datarow
if (e.Row.RowType == DataControlRowType.DataRow)
{
//loop all the cells in the row
for (int i = 0; i < e.Row.Cells.Count; i++)
{
int value = 0;
//try converting the cell value to an int
try
{
value = Convert.ToInt32(e.Row.Cells[i].Text);
}
catch
{
}
//check the value and set the background color
if (value == "")
{
e.Row.Cells[i].BackColor = Color.Green;
}
else
{
e.Row.Cells[i].BackColor = Color.White;
}
}
}
}
Событие OnRowDataBound - это ваша отправная точка. Там вы можете пройти через все ячейки и проверить их ценность. –
Посмотрите [ЗДЕСЬ] (http://stackoverflow.com/questions/31528633/how-to-change-gridview-cell-color-based-on-condition-using-c-sharp/31529889#31529889). – jsanalytics
Можете ли вы показать мне, как именно вы это делаете? –