Finding edititem control names in datagrid at runtime

Discussion in 'ASP .Net Web Controls' started by rohan_p, Oct 15, 2004.

  1. rohan_p

    rohan_p Guest

    I'm trying to make a generic class that will manage an editable datagrid.
    Part of the functionality of the class is that it shouldn't need to know the
    names or types of the input fields - they will get passed in inside a panel,
    and it will loop through the panel's control collection to extract the data
    and create SP parameters on the fly.

    This is OK for inputing (since the input fields are not part of the
    datagrid) and deleting, but I've run into a problem when trying to edit a row
    - I can't find a way of finding out the names of the controls. I can't even
    find out if the controls are in some sort of container.

    Of course, usually you find the edit mode controls by using Findcontrol(),
    but you need to know the control's name. Looping through the controls or
    items collection of the DataGrid doesn't seem to work.

    The only alternative I can think of is to extrace the data in the page and
    store it in some sort of data structure, and pass this in, but it isn't what
    I had in mind.

    Is there any way to get references to the EditItem controls at runtime?
    rohan_p, Oct 15, 2004
    #1
    1. Advertising

  2. rohan_p

    rohan_p Guest

    I figured out one way to doing it. Perhaps there are simpler ones:

    For i As Integer = 0 To grid.Items.Count - 1
    Select Case grid.Items(i).ItemType
    Case ListItemType.EditItem
    'Get the cells of the editable row
    Dim tccCells As TableCellCollection = grid.Items(i).Cells

    For j As Integer = 0 To tccCells.Count - 1
    Dim tcCell As TableCell = tccCells.Item(j)
    'Get the child controls of each cell
    Dim colControls As ControlCollection = tcCell.Controls
    'Examine each control type
    For k As Integer = 0 To colControls.Count - 1
    Select Case GetControlType(colControls.Item(k))
    'library function
    Case "TextBox"
    Dim t As TextBox = colControls.Item(k)
    recordset.AddParameter("@" &
    GetFieldName(t.ID), Trim(t.Text))
    Exit Select

    <-- Other cases -->

    Case Else
    Exit Select
    End Select
    Next
    Next
    Exit Select
    End Select
    Next
    rohan_p, Oct 18, 2004
    #2
    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. Shane O. Pinnell
    Replies:
    0
    Views:
    441
    Shane O. Pinnell
    Jul 9, 2003
  2. Lars Netzel
    Replies:
    1
    Views:
    451
    Lars Netzel
    Jul 30, 2004
  3. =?Utf-8?B?eXVjaGFuZw==?=
    Replies:
    0
    Views:
    527
    =?Utf-8?B?eXVjaGFuZw==?=
    Apr 15, 2006
  4. Shane O. Pinnell

    Error Binding DropDownList on EditItem Command of DataGrid Control

    Shane O. Pinnell, Jul 9, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    178
    Shane O. Pinnell
    Jul 9, 2003
  5. James Cooke
    Replies:
    0
    Views:
    227
    James Cooke
    Sep 11, 2008
Loading...

Share This Page