This is a migrated thread and some comments may be shown as answers.

Grid cell selection

1 Answer 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zhangzhen
Top achievements
Rank 1
Zhangzhen asked on 13 Oct 2011, 08:50 AM
Hi,

I want to select some particular cells (note, not the whole row) in the grid and then in the code behind, I want to get which cells have been selected and do something for these cells. Is there any easy way to achieve this? For the cells selected, they may not be in the same row. It will be great if I can select cells by selecting a range in the grid by dragging the mouse. Could you please advice?

Thanks in advance,
Dong, Zhangzhen

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Oct 2011, 11:30 AM
Hello Zhangzhen,

You can attatch the cell clicking event from the ItemDataBound. And from that function you can make the ajaxRequest with required parameters and can do the server side functionality.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
 {
     foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
    {
     GridDataItem dataItem = (GridDataItem)e.Item;
     dataItem[col.UniqueName].Attributes.Add("onclick", "CellClick('" + dataItem.ItemIndex + "','" + col.UniqueName + "');");
    }
  }
}

JS:
<script type="text/javascript">
 function CellClick(index, uniqueName)
 {
    var grid = $find("<%=RadGrid1.ClientID %>");
    var MasterTable = grid.get_masterTableView();
    var row = MasterTable.get_dataItems()[index];
    var cell = MasterTable.getCellByColumnUniqueName(row, uniqueName);
    var celltext = cell.innerHTML;
    cell.style.borderColor = "Red";
    alert(celltext);
    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest(uniqueName);
 }
</script>
C#:
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
 {
     //access the argument do your code
 }

Thanks,
Princy.
Tags
Grid
Asked by
Zhangzhen
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or