Click here to Skip to main content
15,356,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a DataGrid and need to change the color of the row in datagrid on clicking the Delete LinkButton in Datagrid.

Please help.

db7uk 29-May-12 4:27am
Will this not defeat the object? when you click delete, will the row not get deleted and your color with it?
Adwaitam 29-May-12 4:57am
i don't want to delete it
Sandeep Mewara 29-May-12 5:38am
web? winforms? what?

So, you want to highlight a row on delete click?
Adwaitam 29-May-12 8:23am
exactly...for Webforms

1 solution

You can do the following by Injecting Javascript function on onClick of link button for a grid row.

For injecting JS, you need to use RowDataBound of GridView, something like:
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
   DataControlRowType rtype = e.Row.RowType;  
   if (rtype == DataControlRowType.DataRow && rtype != DataControlRowType.Footer
       && rtype != DataControlRowType.Separator && rtype != DataControlRowType.Header
       && rtype != DataControlRowType.Pager)  
      // Highligh row on click of row
      e.Row.Attributes.Add("onclick", "Highlight(this);");

Modify it for any event like mouseover or link button click, etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900