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

[Solved] Drop Down list double loading

1 Answer 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 28 Feb 2013, 07:08 PM
I have a drop down list in a radgrid and on edit mode or insert mode it needs to load it.  That's all taken care of however what it does in insert mode is loads the dropdown list with both SQL statements, and I am rather perplexed of why this happens since they are 2 different modes of The grid.

Protected Sub myRadGrid_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles myRadGrid.ItemDataBound
       If (TypeOf e.Item Is IGridInsertItem AndAlso e.Item.IsDataBound) Then
           Dim Region As DropDownList = DirectCast(e.Item.FindControl("ddlRegion"), DropDownList)
           sql = "Select intRegionID, strRegionCode from Region where bitActive = 1"
 
           Region.Items.Add(New ListItem("Pick Region", "0"))
           buildDD(sql, Region)
       End If
 
       If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then
           Dim Item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
           Dim Region As DropDownList = DirectCast(Item.FindControl("ddlRegion"), DropDownList)
 
           sql = "Select intRegionID, strRegionCode from Region"
 
           Region.Items.Add(New ListItem("Pick Region", "0"))
           buildDD(sql, Region)
 
           Region.SelectedValue = DirectCast(DataBinder.Eval(e.Item.DataItem, "intRegionid").ToString(), String)
 
       End If
   End Sub

So when in insert mode it shows the resulsts of both sql statements and not just the

IGridInsertItem mode.

 

 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Mar 2013, 06:55 AM
Hi,

Please take a look into the following code snippet to Populate the DropDownList with different data in Edit and insert mode.

VB:
Private Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
                ' Code for populating the DropDownList in insert mode
        If TypeOf e.Item Is GridEditFormInsertItem OrElse TypeOf e.Item Is GridDataInsertItem Then
                ' Code for populating the DropDownList in edit item
        Else
        End If
    End If
End Sub

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