I’m trying to determine the column of a cell.
I have a _ItemDataBound event in my code where I change the color of the cell based of the value (.text) …no big deal.
But now I need to determine in which column a cell is. Because I need to call a stored procedure to get some additional values, but I just need to do that for all rows of one column and not for all of them.
How can I determine if a cell is in the column where I have to call the procedure?
Thanks for any hint
5 Answers, 1 is accepted
That would depend greatly upon what you are getting the "ItemDatabound" event from. I suspect you are referring to a radGrid control however your notes are not very specific.
Assuming you are using a RadGrid, the item databound is more of a "row databound" event. You get a GridDataItem object which points to object getting data bound. You can cast this several ways one of which provides you easy access to the "Datakeyvalues" collection. In code I have written, I use a "keyvalue" to provide a database id to lookup values with. I then perform the related database query, find relevant values, and then adjust things based upon those values. The grid data item provides access to the various columns, of the row being data bound, via the unique name of the column.
The documentation is actually helpful along these lines!
Thanks for your reply.
Sorry I forgot to write that I’m using a radgrid.
As I understand it right, in your solution you do the lookup in every cell ? My idea is to do it just in all cells for a defined column to avoid non necessary operations.
I used already the key value of a row for other things, but in that case would need the Column as well.
If there is no option do determine the column of a cell I can return from the DB a concatenated value like “CheckVal:15.4” . This value I can parse and if I get one with “CheckVal” in sting I could do a split on “:” and use the value “15.4”
But I would prefer a nicer way :-)
You seem to be fixated on the "cell" versus the data row. The ItemDataBound event, on the RadGrid, is on a per row basis, not a per-cell basis. Here is a sample of code where I change the tooltips and background of individual cells on the current row based upon business rules. This is done "on the fly" row by row as data is bound to the grids elements.
This might give you some ideas. I remind you that the fields I have identified as "GLAccount", and "ProjectCode" refer to the "UniqueName" values from grids markup.
@David, thanks for the suggestions and for sharing your specific approach.
@Dennis, you can examine the following article, which demonstrates how you can access an individual cell using the UniqueName of a column:
The reverse action, i.e. determining the column name using the cell element, can be achieved as follows:
But I think there are very limited practical uses of this approach.
Hope this information helps.
Hi David, Hi Eyup
thanks for your help.
i was thinking the wrong way. it works fine with the GridDataItem for each row.
thanks a lot