Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Datagrid Header from TableCell

Reply
Thread Tools

Datagrid Header from TableCell

 
 
DanG
Guest
Posts: n/a
 
      05-22-2008
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,
DataGrid).Columns(i).HeaderText
End If
Next
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.

Thanks
Dan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
datagrid having row header and column header krishna.dwivedi@gmail.com ASP .Net Datagrid Control 0 07-13-2006 08:20 AM
Any way to reorder how a datagrid is drawn (header/footer/items vs.header/items/footer)? Henrik ASP .Net Datagrid Control 1 07-06-2006 12:23 AM
referencing a TableCell in a bound datagrid MattB ASP .Net 3 05-04-2004 02:21 AM
TableCell oTableCell = new TableCell(); noWrap? Brian K. Williams ASP .Net 2 04-30-2004 12:04 AM



Advertisments