Gridview - is individual cell click event possible?

K

K B

I would like to create a gridview as below:

Project Name 1-1 1-2 1-3 1-4 1-5 1-6
Project 1 BLUE BLUE BLUE BLUE GREEN GREEN
more projects

I would like to fill the cell with a solid color based on the value of
the cell (e.g., documents that are complete (blue) or not complete
(green). In effect have a solid bar indicator going across each row. I
know how to color the cell based on the value, but not the click part.

Is there any way to do this so that I can then get row/cell information
based on the CELL clicked? I will need to retrieve the column title and
value of the cell as well as the first column value.

Any direction GREATLY appreciated!

Thanks,
Kit
 
E

Eliyahu Goldin

You can do it easily with a bit of javascripting.

Make 3 hidden fields:
<input runat=server type=hidden id=inhAction />
<input runat=server type=hidden id=inhRow />
<input runat=server type=hidden id=inhColumn />

and a javascript function:
function cellClicked(row, column){
myForm.inhAction.value = "CELLCLICKED";
myForm.inhRow.value = row;
myForm.inhColumn.value = column;
myForm.submit();
}

and in the gridview's RowDataBound event setup the javascript call for every
cell:
myCell.Attributes["onclick"]=String.Format("cellClicked({0},{1})",
myCellRow, myCellColumn);

When you click a cell, you will get a postback. You can tell taht the
postback is caused by a cell click by looking in the inhAction and you can
get the row and the column numbers from the inhRow and inhColumn.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top