On RadGrid, user can click on cell and changes background color of the cell from nothing to "Green" . Any help is highly appreciated..
Javascript code..
<script type="text/jscript">
/*
It enables click functionality on the grid CELL..
*/
function CellClick(index, uniqueName) {
var grid = $find("<%=gridWord.ClientID %>");
var MasterTable = grid.get_masterTableView();
var row = MasterTable.get_dataItems()[index];
var cell = MasterTable.getCellByColumnUniqueName(row, uniqueName);
var celltext = cell.innerHTML;
if (cell.style.backgroundColor == "green") {
cell.style.backgroundColor = "";
}
else {
cell.style.backgroundColor = "green";
}
}
</script>
code behind snippet -
protected void gridWord_ItemDataBound(object sender, GridItemEventArgs e)
{
//This bit enables JavaScript Click Event..
if (e.Item is GridDataItem)
{
foreach (GridColumn col in gridWord.MasterTableView.RenderColumns)
{
GridDataItem dataItem = (GridDataItem)e.Item;
dataItem[col.UniqueName].Attributes.Add("onclick", "CellClick('" + dataItem.ItemIndex + "','" + col.UniqueName + "');");
}
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
foreach (GridDataItem item in gridWord.MasterTableView.Items)
{
//Hard -code to get the BackColor of the cell..
TableCell cell = item["1"];
lblError.Text = cell.BackColor.Name;
}
}
cell.BackColor.Name always returns 0 even when the cell has "Green" background color.
FYI, RadGrid has only one ROW with multiple Columns.
Many thanks.
Milan G