Results 1 to 2 of 2

Thread: gridView RowEditing

  1. #1

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    gridView RowEditing

    I have the follwoing function which loops through 3 datagrids on my page and should disable all other edit buttons when one edit button is clicked.

    VB Code:
    1. Protected Sub DisableEdit()
    2.         Dim c As Control
    3.         Dim content As ContentPlaceHolder
    4.         content = Page.Master.FindControl("contentplaceholder1")
    5.  
    6.         Dim grid As GridView
    7.         Dim frow As GridViewRow
    8.  
    9.         For Each c In content.Controls
    10.             If c.GetType() Is GetType(GridView) Then
    11.                 grid = CType(c, GridView)
    12.                 For Each frow In grid.Rows
    13.                     If (frow.RowType = DataControlRowType.DataRow) Then
    14.                         If Not frow.RowState = DataControlRowState.Edit Then
    15.                             Dim btnEdit As LinkButton = frow.Cells(8).Controls(0)
    16.                             btnEdit.Enabled = False
    17.                         End If
    18.                     End If
    19.                 Next
    20.             End If
    21.         Next
    22.  
    23.     End Sub

    I call this on the RowEditing of each gridview, unfortunately RowEditing Occurs when a row's Edit button is clicked, but before the GridView control enters edit mode. Which means it turns them all to false but re-binds the gridview that called the fucntion, which in turn renders all fo the controls visible.

    Does anyone know of a workaround for this, or the correct event to use that will fire after the control enters edit mode

  2. #2

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Re: gridView RowEditing

    I have decided to write a seperate function that will be called on page_prerendercomplete. This is the code:

    VB Code:
    1. Protected Sub DisableEdits()
    2.         Dim c As Control
    3.         Dim content As ContentPlaceHolder
    4.         content = Page.Master.FindControl("ContentPlaceHolder1")
    5.         Dim EditOn As Boolean = False
    6.  
    7.         Dim grid As GridView
    8.         Dim frow As GridViewRow
    9.  
    10.         For Each c In content.Controls
    11.             If c.GetType() Is GetType(GridView) Then
    12.                 grid = CType(c, GridView)
    13.                 For Each frow In grid.Rows
    14.                     If (frow.RowType = DataControlRowType.DataRow) Then
    15.                         If frow.RowState = DataControlRowState.Edit Then
    16.                             EditOn = True
    17.                         End If
    18.                     End If
    19.                 Next
    20.             End If
    21.         Next
    22.  
    23.         If EditOn = True Then
    24.             For Each c In content.Controls
    25.                 If c.GetType() Is GetType(GridView) Then
    26.                     grid = CType(c, GridView)
    27.                     For Each frow In grid.Rows
    28.                         If (frow.RowType = DataControlRowType.DataRow) Then
    29.                             If Not frow.RowState = DataControlRowState.Edit Then
    30.                                 Dim btnEdit As LinkButton = frow.Cells(9).Controls(0)
    31.                                 btnEdit.Enabled = False
    32.                             End If
    33.                         End If
    34.                     Next
    35.                 End If
    36.             Next
    37.         Else
    38.             For Each c In content.Controls
    39.                 If c.GetType() Is GetType(GridView) Then
    40.                     grid = CType(c, GridView)
    41.                     For Each frow In grid.Rows
    42.                         If (frow.RowType = DataControlRowType.DataRow) Then
    43.                             'If Not User.IsInRole(frow.DataItem("Number").ToString) Then
    44.                             Dim btnEdit As LinkButton = frow.Cells(9).Controls(0)
    45.                             btnEdit.Enabled = True
    46.                             'End If
    47.                         End If
    48.             Next
    49.                 End If
    50.             Next
    51.         End If
    52.  
    53.     End Sub

    this loops through all 3 of my gridviews, if any of the command buttons are set to edit, its turns a boolean to false, whch in turn disables all other edit buttons. If boolean remains true all edit buttons are set to active.

    This works but I am getting a strange problem, if i click the first edit button the others disable, then when i click 'save' or 'cancel' the others are activated again which works perfectly.

    However the second link button doesnt work, then the third one does then the fourth one doesnt etc.

    any clues?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width