Datagrid Header from TableCell

Discussion in 'ASP .Net' started by DanG, May 22, 2008.

  1. DanG

    DanG Guest

    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
     
    DanG, May 22, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian K. Williams

    TableCell oTableCell = new TableCell(); noWrap?

    Brian K. Williams, Apr 30, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,537
    Brian K. Williams
    Apr 30, 2004
  2. MattB
    Replies:
    3
    Views:
    2,549
    MattB
    May 4, 2004
  3. mlt
    Replies:
    2
    Views:
    863
    Jean-Marc Bourguet
    Jan 31, 2009
  4. Henrik
    Replies:
    1
    Views:
    433
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
  5. datagrid having row header and column header

    , Jul 13, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    185
Loading...

Share This Page