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

OnSelectedIndexChanged for editin inplace Grid drop down list

7 Answers 145 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 23 Jan 2012, 01:28 AM
I have a nice grid working, and in place add,edit and delete working great.

However I am now trying to get a drop down list to trigger the "OnSelectedIndexChanged" event so I can obtain the cost and sell price of the part and place it in the appropriate fields.

<Columns>
                                                                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
                                                                        CancelImageUrl="~/Images/cancel_16x16.png" EditImageUrl="~/Images/edit_16x16.png"
                                                                        InsertImageUrl="~/Images/update_16x16.png" UpdateImageUrl="~/Images/update_16x16.png"
                                                                        HeaderStyle-Width="50px">
                                                                        <ItemStyle CssClass="MyImageButton" />
                                                                    </telerik:GridEditCommandColumn>
                                                                    <telerik:GridDropDownColumn DataField="PartId" DataSourceID="qry_Parts" HeaderText="Part"
                                                                        ListTextField="Description" ListValueField="PartId" UniqueName="EditPartId" ColumnEditorID="GridDropDownColumnEditorParts"
                                                                        EnableEmptyListItem="False" HeaderStyle-Width="320px">
                                                                    </telerik:GridDropDownColumn>

Neither the GridBouncColumn or the referering ColumnEditor allow this event.

How can I achive this?

Thanks in advance.

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Jan 2012, 05:17 AM
Hello Jason,

Try setting DropDownControlType as RadComboBox and attach the event as shown below.
C#:
protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name=="")
  {
    GridEditableItem item = (GridEditableItem)e.Item;
    RadComboBox combo = (RadComboBox)item["EditPartId"].Controls[0];
    combo.AutoPostBack = true;
    combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged);
  }
}
 void combo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
}

-Shinu.
0
Jason
Top achievements
Rank 1
answered on 23 Jan 2012, 11:44 PM
Do you have that solution in VB.

Thanks
0
Jason
Top achievements
Rank 1
answered on 08 Feb 2012, 07:01 AM
In VB :

combo.SelectedIndexChanged = New RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged)

does not work as "SelectedIndexChanged" is not available from list. "OnClientSelectedIndexChanged" is though.

Pls help.

Thanks.
0
Shinu
Top achievements
Rank 2
answered on 08 Feb 2012, 08:23 AM
Hello Jason,

Here is the code in VB.
VB:
Protected Sub grid_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode AndAlso e.Item.OwnerTableView.Name = "" Then
        Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim combo As RadComboBox = DirectCast(item("EditPartId").Controls(0), RadComboBox)
        combo.AutoPostBack = True
        combo.SelectedIndexChanged += New RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged)
    End If
End Sub
Private Sub combo_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
End Sub

Here is the link for code-converter.
http://converter.telerik.com/.

-Shinu.
0
Jason
Top achievements
Rank 1
answered on 09 Feb 2012, 02:05 AM
Shinu,

Thanks however I believe your conversion is not total correct. I can get this to compile ok, but when I run it , all get is a postback but nothing happens, it doesn't run the "combo_SelectedIndexChanged".

Protected Sub RadGridQuoteItemParts_ItemDataBound(ByVal source As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
 
        If e.Item.IsInEditMode And e.Item.OwnerTableView.Name = "" Then
            Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
            Dim combo As RadComboBox = DirectCast(item("EditPartId").Controls(0), RadComboBox)
 
            combo.AutoPostBack = True
            AddHandler combo.Load, AddressOf combo_SelectedIndexChanged
 
            'MsgBox(combo.SelectedValue & "handler added")
        End If
 
    End Sub
 
    Private Sub combo_SelectedIndexChanged(ByVal source As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)
 
        MsgBox("selected")
 
    End Sub
0
KC
Top achievements
Rank 1
answered on 09 Feb 2012, 02:59 AM
Hi Jason,

Try wiring the event in RadGridQuoteItemParts_ ItemCreated event instead of in the ItemDataBound event.
0
Jason
Top achievements
Rank 1
answered on 09 Feb 2012, 11:26 PM
Protected Sub RadGridQuoteItemLabour_ItemCreated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
 
        If e.Item.IsInEditMode And e.Item.OwnerTableView.Name = "" Then
            Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
            Dim combo As RadComboBox = DirectCast(item("EditLabourRateId").Controls(0), RadComboBox)
 
            combo.AutoPostBack = True
            AddHandler combo.SelectedIndexChanged, AddressOf EditLabourRateId_SelectedIndexChanged
 
        End If
 
    End Sub
 
    Private Sub EditLabourRateId_SelectedIndexChanged(ByVal source As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)
 
        Dim intLabourRateIdToLookup As Integer
        Dim strLabourRatePrices As String
        Dim arrLabourRatePrices() As String
        Dim combo As RadComboBox = DirectCast(source, RadComboBox)
        Dim editItem As GridDataItem = DirectCast(combo.NamingContainer, GridDataItem)
        Dim txtEditGridLabourCostRatePerHour As RadNumericTextBox = DirectCast(editItem("EditGridLabourCostRatePerHour").Controls(0), RadNumericTextBox)
        Dim txtEditGridLabourSellRatePerHour As RadNumericTextBox = DirectCast(editItem("EditGridLabourSellRatePerHour").Controls(0), RadNumericTextBox)
        Dim txtEditGridLabourGSTPercentageToApply As RadNumericTextBox = DirectCast(editItem("EditGridLabourGSTPercentageToApply").Controls(0), RadNumericTextBox)
 
        intLabourRateIdToLookup = e.Value
        'Get Cost and Sell prices
        strLabourRatePrices = returnCostSellPriceForSelectedLabour(intLabourRateIdToLookup)
        arrLabourRatePrices = strLabourRatePrices.Split(";")
 
        'Update Values
        txtEditGridLabourCostRatePerHour.Text = arrLabourRatePrices(0)
        txtEditGridLabourSellRatePerHour.Text = arrLabourRatePrices(1)
        txtEditGridLabourGSTPercentageToApply.Text = arrLabourRatePrices(2)
 
    End Sub
Tags
ComboBox
Asked by
Jason
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jason
Top achievements
Rank 1
KC
Top achievements
Rank 1
Share this question
or