This is a migrated thread and some comments may be shown as answers.

Cannot put columns into edit mode

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Acadia
Top achievements
Rank 1
Iron
Acadia asked on 06 Jun 2012, 03:43 PM
I know this should be simple and I have done it before, but for some reason I can't see why this isn't working.  I have a very small grid with 3 columns and all I want to do is place one of two columns into edit mode in the PreRender method.  If a hidden column in the row is a certain value, I want to place it's corresponding visible column into edit mode and color the first column red.  In debug the values are being compared properly and it does hit the line of code that sets the column into edit mode, however it sets both columns into edit mode for every row instead of the just the column that I want it to (even though it doesn't hit the code to set the other column into edit mode it still somehow is set to edit).  If both hidden columns are invalid I want to set both visible columns into edit mode.  As for coloring the text of the first column red it simply has no effect even thoguh the code is hit.

Can somebody please help me with this it seems like it should be very simple.  Thanks!
Private Sub rgC_PreRender(sender As Object, e As System.EventArgs) Handles rgC.PreRender
 
 
       If Not IsPostBack Then
           For Each item As GridItem In rgC.MasterTableView.Items
 
               If (TypeOf item Is GridDataItem) Then
                   Dim lblEmpId As Label = CType(item.FindControl("lblEmpId"), Label)
                   Dim lblEmpNo As Label = CType(item.FindControl("lblEmpNo"), Label) 'Contains the null value if invalid
 
                   Dim lblJobCode As Label = CType(item.FindControl("lblJobCode"), Label)
                   Dim lblJobNum As Label = CType(item.FindControl("lblJobNum"), Label) 'Contains the null value if invalid
 
                   Dim lblCardId As Label = CType(item.FindControl("lblCardId"), Label)
 
                   If (lblEmpNo.Text = "") Then
                       lblCardId.ForeColor = Drawing.Color.Red
                       item.Edit = True
                   End If
 
                   If (lblJobCode.Text = "") Then
                       lblCardId.ForeColor = Drawing.Color.Red
                       item.Edit = True
                   End If
               End If
 
              
           Next
           rgC.Rebind()
       End If
 
   End Sub

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Jun 2012, 05:15 AM
Hi,

Please take a look into the following sample code snippet I tried to achieve the same scenario.

VB:
Protected Sub Rdagrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim lblEmpId As Label = DirectCast(item.FindControl("lblEmpId"), Label)
        Dim lblEmpNo As Label = DirectCast(item.FindControl("lblEmpNo"), Label)
        'Contains the null value if invalid
 
        Dim lblJobCode As Label = DirectCast(item.FindControl("lblJobCode"), Label)
        Dim lblJobNum As Label = DirectCast(item.FindControl("lblJobNum"), Label)
        'Contains the null value if invalid
 
        Dim lblCardId As Label = DirectCast(item.FindControl("lblCardId"), Label)
 
        If (lblEmpNo.Text = "") Then
            lblCardId.ForeColor = System.Drawing.Color.Red
 
            item.Edit = True
        End If
        If (lblJobCode.Text = "") Then
            lblCardId.ForeColor = System.Drawing.Color.Red
 
            item.Edit = True
        End If
    End If
End Sub

Thanks,
Shinu.
Tags
Grid
Asked by
Acadia
Top achievements
Rank 1
Iron
Answers by
Shinu
Top achievements
Rank 2
Share this question
or