In datagrid view select cells want to highlightcolor?
While click on the cells in the datagrid view want to be change in color.and also undo the selected cells
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
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 attend4days leftRegister
Joginder BangerRank #360 · 7K reputationPosted Feb 13, 2015, 8:07 AM EST
try this one
protected void btn_GrdClick(object sender, EventArgs e)
{
if(Session["PreviousRowIndex"] != null)
{
var previousRowIndex = (int)Session["PreviousRowIndex"];
GridViewRow PreviousRow = MyGridView.Rows[previousRowIndex];
PreviousRow.ForeColor = Color.White;
}
GridViewRow row = (GridViewRow)((Button)sender).NamingContainer;
row.ForeColor = Color.Yellow; Session["PreviousRowIndex"] = row.RowIndex;
}