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

disable dropdownlists on edit mode not insert mode

2 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 11 Apr 2012, 08:37 PM

I have a couple of dropdownlists on my forTemplate but the fucntionality I need is the following.  On Insert I need them to be avialable to pick data, but on Edit mode I want to disable them so that they cannot mess with them becuase they are not editable in edit mode.  i thought the follwoing code would work but appears not.  On insert mode or what i thought was insertmode it fills the ddl and it works for soem reason, but on edit or insert it disables my dropwdownlists. 

Protected Sub myPOGrid_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles myPOGrid.ItemDataBound
       If (TypeOf e.Item Is IGridInsertItem AndAlso e.Item.IsDataBound) Then
           Dim gr As DropDownList = DirectCast(e.Item.FindControl("ddlPOFund"), DropDownList)
           sql = "Select intFundID, strPGMCDnum + ' \ ' + CASE WHEN intSourceId = 1 then 'FEDERAL' ELSE 'STATE' END + ' \ ' + strEorNum FUND from Drat_fundSource where bitArchive IS NULL"
           gr.Items.Add(New ListItem("Pick Funding Source", "0"))
           buildDD(sql, gr)
       End If
       If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
           Dim editedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
           Dim PoFund As DropDownList = DirectCast(editedItem.FindControl("ddlPOFund"), DropDownList)
           Dim FundS As DropDownList = DirectCast(editedItem.FindControl("ddlFundSource"), DropDownList)
           PoFund.Enabled = False
           FundS.Enabled = False
       End If
   End Sub

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 12 Apr 2012, 05:00 AM
Hello Kevin,

Try the following code snippet to achieve your scenario.
VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If e.Item.OwnerTableView.IsItemInserted AndAlso TypeOf e.Item Is GridEditFormInsertItem Then
        'item is about to be inserted 
        Dim insertItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
        Dim ddl As DropDownList = DirectCast(insertItem.FindControl("ddlPoFund"), DropDownList)
        ddl.Enabled = True
    End If
    If Not (TypeOf e.Item Is GridEditFormInsertItem) AndAlso e.Item.IsInEditMode Then
        'item is about to be edit
        Dim editItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
        Dim ddl As DropDownList = DirectCast(editItem.FindControl("ddlPoFund"), DropDownList)
        ddl.Enabled = False
    End If
End Sub

Thanks,
Shinu.
0
Kevin
Top achievements
Rank 1
answered on 12 Apr 2012, 03:57 PM
Awesome, thank you
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Share this question
or