How to FindControl in DataGrid ItemCommand

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zuhaib

    How to FindControl in DataGrid ItemCommand

    Hello Every One:
    Can some one give me iDeas How do I disable the DataGrid controls in ItemCommand using VB.
    For Example I have dropdownlist bound in my DataGrid. Now I want to Disable this control in Datagrid_ItemCo mmand.
    I tried like this
    ''''''''''''''' ''''''''''''''
    Code:
    Select Case e.CommandName
    
                Case "Edit" '//Edit Case
    
                
    
                    dgIncentive.EditItemIndex = e.Item.ItemIndex
    
                    Dim ddlOwner, ddlUser As DropDownList
    
                                             '' Disable ddlOwnerNett And ddlUserNet ''
    
                    Dim str_Sql As String = "SELECT manager FROM Inc_Agency_Header " & _
    
                                            " WHERE Incentive_ID = '" & ddlIncentive.SelectedValue & "'"
    
                    Dim dsManager As DataSet = DataProvider.GetDataInterface.ExecuteQuery(str_Sql)
    
                    If dsManager.Tables(0).Rows.Count > 0 Then
    
                        If dsManager.Tables(0).Rows(0).Item("Manager") = 0 Then
    
                         ddlUser = CType(e.Item.Cells(15).FindControl("edit_ddlUserNett"), DropDownList)
    
                            ddlUser.Enabled = True
    
                        End If
    
                    End If
    ''''''''''''''' ''''''''''''''
    But Unfortunately

    CType(e.Item.Ce lls(15).FindCon trol("edit_ddlU serNett"), DropDownList)

    returning "Nothing".

    Thanx

    Regards
  • khurramzeb
    New Member
    • Oct 2010
    • 8

    #2
    Hi Zohaib

    If you use
    CType(e.Item.Fi ndControl("edit _ddlUserNe tt"), DropDownList)

    instead of

    CType(e.Item.Ce lls(15).FindCon trol("edit_ddlU serNe tt"), DropDownList)

    it will work because the dropdownlist control dosenot belong to cell it only belongs to row, so need to refrence Cells(15)

    Comment

    Working...