Ask fill color Text in a Grid View, Grid View data is loaded, the highlighters in grid view under one condition such as larger amounts 1.000 or character as mas ... see attached image file
Loading
Ask fill color Text in a Grid View, Grid View data is loaded, the highlighters in grid view under one condition such as larger amounts 1.000 or character as mas ... see attached image file
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 19, 2015, 3:00 AM EDT
as i understadnd you want to change row color
then
on gridview Rowdatabound event
if (e.Row.RowType == DataControlRowType.DataRow) {
if (convert.ToInt32(e.Row.Cells[2].Text)>1)
{
e.Row.Cells[2].ForeColor = System.Drawing.Color.Yellow;
}
}
Dong Lam TrienRank #1,538 · 1K reputationPosted Mar 19, 2015, 6:01 PM EDT
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 19, 2015, 7:39 PM EDT
your image is not opening in your link
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 19, 2015, 7:50 PM EDT
take label in your column and bind amount on that label and on row databound event
find control of that label and change label color dynamically based on condition
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 21, 2015, 3:13 AM EDT
Dong Lam TrienRank #1,538 · 1K reputationPosted Mar 22, 2015, 8:47 PM EDT
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 22, 2015, 9:04 PM EDT
Dong Lam TrienRank #1,538 · 1K reputationPosted Mar 23, 2015, 5:31 PM EDT
Joginder BangerRank #360 · 7K reputationPosted Mar 23, 2015, 9:00 PM EDT
foreach (DataGridViewRow row in mydataGridView.Rows)
{ string RowType = row.Cells[0].Value.ToString();
if (RowType == "Type A")
{ row.DefaultCellStyle.BackColor = Color.Red; row.DefaultCellStyle.ForeColor = Color.White; }
else if (RowType == "Type B")
{ row.DefaultCellStyle.BackColor = Color.Yellow; row.DefaultCellStyle.ForeColor = Color.Black;
}
}
Dong Lam TrienRank #1,538 · 1K reputationPosted Mar 24, 2015, 8:57 PM EDT
[code]
private void txtSearchby_TextChanged(object sender, EventArgs e)
{
DataView dv = new DataView(dt); // dataTable
String filter = String.Format(Name LIKE '%{0}%' Or HomePhone LIKE '%{0}%' ,...., txtSearchby.Text);
dv.RowFilter = filter;
dataGridView1.DataSource = dv;
// Fill Highttext Color ?
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string RowType = row.Cells[0].Value.ToString(); // Error here: Object reference not set to an instance of an object.
if (RowType == txtSearchby.Text)
{
row.DefaultCellStyle.BackColor = Color.Yellow;
row.DefaultCellStyle.ForeColor = Color.White;
}
}
}
[/code]
Joginder BangerRank #360 · 7K reputationPosted Mar 24, 2015, 9:12 PM EDT
Row.Cells[0].Value.ToString();
Dong Lam TrienRank #1,538 · 1K reputationPosted Mar 25, 2015, 12:24 AM EDT
[code]
....
}