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

new row and combobox events

4 Answers 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Juan
Top achievements
Rank 1
Juan asked on 18 Sep 2008, 03:33 PM
hi at  all

i have a problem with rad combobox events on radgrid .

i have two radcombobox in a column template on a  radgrid,
when a change the selected item in the firts radcombobox
the elements of the second radcombobox must be change.
I did it, but only works when the grid is in editmode,
but not when the grid created a new item , what can i do what's wrong in my code.
(i'am usig radcontrols 2008 q1,vs2005 and vb)

Protected Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated 
    If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then 
        Dim list As RadComboBox = CType(CType(e.Item, GridEditableItem)("TemplateColumn").Controls(1), RadComboBox) 
        list.AutoPostBack = True 
        AddHandler list.SelectedIndexChanged, AddressOf Me.list_SelectedIndexChanged          
 
    End If 
End Sub 
Private Sub list_SelectedIndexChanged(ByVal sender As ObjectByVal e As RadComboBoxSelectedIndexChangedEventArgs) 
    
    Dim editedItem As GridEditableItem = CType(CType(sender, RadComboBox).NamingContainer, GridEditableItem) 
  
    Dim ddList As RadComboBox = CType(editedItem("NroCelular").Controls(1), RadComboBox) 
    
    Dim sql As String = "SELECT [NroCelular] FROM [Celulares] WHERE idUsuario=@idUsuario ORDER BY [NroCelular] " 
    Dim parameters As New Collection 
    Dim parameter1 As New OleDbParameter 
    parameter1.ParameterName = "@idUsuario" 
    parameter1.OleDbType = OleDbType.Integer 
    parameter1.Value = CType(editedItem("TemplateColumn").Controls(1), RadComboBox).SelectedValue 
    parameters.Add(parameter1) 
    ddList.Items.Clear() 
    Dim table As DataTable = dbManager.getDataTable(sql, parameters) 
    Dim row As DataRow 
    For Each row In table.Rows 
        Dim item As New RadComboBoxItem(row(0), row(0)) 
        ddList.Items.Add(item) 
    Next 
End Sub 
Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound 
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then 
        Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem) 
        Dim editMan As GridEditManager = editedItem.EditManager 
        Dim editor As GridTemplateColumnEditor = CType(editMan.GetColumnEditor("NroCelular"), GridTemplateColumnEditor) 
        Dim ddlOrderIDcombo As RadComboBox = CType(editedItem("TemplateColumn").Controls(1), RadComboBox) 
        Dim sql As String = "SELECT [NroCelular] FROM [Celulares] WHERE idUsuario=@idUsuario ORDER BY [NroCelular] " 
        Dim parameters As New Collection 
        Dim parameter1 As New OleDbParameter 
        parameter1.ParameterName = "@idUsuario" 
        parameter1.OleDbType = OleDbType.Integer 
        parameter1.Value = CType(editedItem("TemplateColumn").Controls(1), RadComboBox).SelectedValue 
        parameters.Add(parameter1) 
        Dim table As DataTable = dbManager.getDataTable(sql, parameters) 
        Dim ddList As RadComboBox = CType(editedItem("NroCelular").Controls(1), RadComboBox) 
        ddList.DataSource = table 
        ddList.Items.Clear() 
        Dim row As DataRow 
        For Each row In table.Rows 
            Dim item As New RadComboBoxItem(row(0), row(0)) 
            ddList.Items.Add(item) 
        Next 
    End If 
End Sub 
this is my code from server side

<telerik:GridTemplateColumn DataField="NombreCompleto" FilterImageToolTip="Filtrar" 
    HeaderText="Usuario" SortExpression="NombreCompleto" UniqueName="TemplateColumn"
    <ItemTemplate> 
        <asp:Label ID="Label3" runat="server" Text='<%# Eval("NombreCompleto") %>'></asp:Label> 
    </ItemTemplate> 
    <EditItemTemplate> 
        <telerik:RadComboBox ID="cmbUsuario" runat="server" DataSourceID="dsUsuarios" DataTextField="NombreCompleto" 
            DataValueField="idUsuario" 
            SelectedValue='<%# Bind("idUsuario") %>' Skin="WebBlue" Width="200px"   > 
            <CollapseAnimation Duration="200" Type="OutQuint" /> 
        </telerik:RadComboBox> 
    </EditItemTemplate> 
</telerik:GridTemplateColumn> 
<telerik:GridTemplateColumn DataField="NroCelular" FilterImageToolTip="Filtrar" HeaderText="Nro Celular" 
    SortExpression="NroCelular" UniqueName="NroCelular"
    <ItemTemplate> 
        <asp:Label ID="Label2" runat="server" Text='<%# Eval("NroCelular") %>'></asp:Label> 
    </ItemTemplate> 
    <EditItemTemplate> 
        <telerik:RadComboBox ID="cmbNroCelular" runat="server" Skin="WebBlue" Width="200px"    > 
            <CollapseAnimation Duration="200" Type="OutQuint" /> 
             
        </telerik:RadComboBox> 
    </EditItemTemplate> 
</telerik:GridTemplateColumn> 

this is my code from the client side




4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 22 Sep 2008, 12:38 PM
Hi Juan,

You have attached the event handler only if the grid item is in edit mode:

if (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then

You can do the same with GridEditFormInsertItem/GridDataInsertItem or attach the event handler declaratively.

Sincerely yours,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Juan
Top achievements
Rank 1
answered on 23 Sep 2008, 02:11 AM
hi

I dont understand you, because
I am doing the same thing that you are
to explain
and with
GridEditFormInsertItem I get the same result.
only work in the edit but not when I am adding a new row





0
Iana Tsolova
Telerik team
answered on 25 Sep 2008, 12:27 PM
Hello Juan,

Could you please elaborate more on your scenario? Do you receive any errors when inserting records with RadGrid or just the RadComboBoxes are not working as expected?

Find more information about RadGrid inserting functionality here.

Let me know if you need further directions/help.

Regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Juan
Top achievements
Rank 1
answered on 07 Oct 2008, 05:07 PM
i found the problem, it was my mistake

when i create a new row , i have  validator components, then the validators donĀ“t allow make a postback , that the reason why the combox not update its values
Tags
Grid
Asked by
Juan
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Juan
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or