Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to All,

I have dataGridview when i click on any row in datagridview i want to change that row color.. please help me with sample code...


Thanking you..
Posted

1 solution

Put a link button in grid view and give its
C#
commandname="ChangeColor" commandgrgumen=<%EVal("sno") text="Change"

Sno is serial number of the table starts from zero
C#
int index= int.Parse(e.CommandArgument.ToString());

in gridviewcommand event write below
C#
if(e.commandName=="CahngeColor")
{  
   griview1.rows[index].backcolor= System.Drawing.Color.Red;
}
 
Share this answer
 
v2
Comments
kulbhushan18 4-Oct-12 11:32am    
griview1.rows[index].CssClass can also be used, for more customization
NARAYANA0509 8-Oct-12 1:55am    
Here i got error at rows[index] what can i do?
Samsani.v.s.Durga Prasad 8-Oct-12 4:45am    
commandname="ChangeColor" commandgrgumen=<%EVal("sno") text="Change"

sno is a column in the table it should start from zero. you should insert the sno in the table from zero why because gridview row index starts from zero. To find out on which row you click, this sno will useful.
for example
if you click on 1st row index will come as 1 (this 1 will come from database table) like this
all rows
Samsani.v.s.Durga Prasad 8-Oct-12 8:57am    
griview1.rows[2]backcolor=System.Drawing.Color.Red;

Above code is not good because if you click on any row 2nd row color only will be changed.

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