Datagrid Header from TableCell



During grid field validation, I would like to generate a message for
the user to tell which column had the error. So I have a control
(textbox, dropdownlist, checkbox, etc.), and would like to grab the
header text from its column. I can't find any direct link from the
TableCell (the control's parent) to the table column.

I know the TableCell has a ClientID, and the last chars will be a
number, but that number doesn't always represent the actual column.
Some of the left-side columns of my grid are sometimes hidden
(display=none), and the number in the TableCell.clientID relates only
to the visible columns. So I can't count on the TableCell number
telling me the right column number.

In the code here, I loop through the DataGridItem cells, counting
columns, until I find the right TableCell.

Public Function GetColumnName(ByVal obj As Object) As String
Dim i As Integer
For i = 0 To CType(obj.parent.parent,
DataGridItem).Cells.Count - 1
If CType(obj.parent, TableCell).ClientID =
CType(obj.parent.parent, DataGridItem).Cells(i).ClientID Then
Return CType(obj.Parent.Parent.Parent.Parent,
End If
Return ""
End Function

The code works fine, but I was hoping for a more elegant solution. Is
there one?

I'm using .NET Framework v1.1.



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