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

Locate row and cell

3 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dhuss
Top achievements
Rank 1
dhuss asked on 19 Dec 2012, 03:10 PM
Is there a way in server side code (vb.net) to go to a specfic row and column in a grid. An example, I have a grid with 20 rows and 10 columns. I would like to go to row 12, column 7 and hi-light that cell without having to iterate through the grid to locate the specfic row/column. Any suggestions would be appreciated.

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Dec 2012, 05:02 AM
Hi,

Try accessing cells as shown below.
VB:
Protected Sub RadGrid2_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        item("Uniquename").ForeColor = System.Drawing.Color.Red
    End If
End Sub

Thanks,
Princy.
0
dhuss
Top achievements
Rank 1
answered on 20 Dec 2012, 02:30 PM
Wouldn't this code loop for each row and set the forecolor for every cell with the unique name of "UniqueName", i.e. the entire column. I only want to color a single cell in a single row without having to loop through every row to find a specific row and then the cell in the row.
0
Princy
Top achievements
Rank 2
answered on 21 Dec 2012, 05:06 AM
Hi,

Please try following code snippet to give color for the 7th cell of 12th row.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem ditem = (GridDataItem)e.Item;
        if (ditem.ItemIndex == 2)
        {
            ditem.Cells[12].BackColor = Color.Red;
        }
    }
}

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