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

[Solved] Set the DefaultValue from a combo box

3 Answers 202 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 2
Stefan asked on 23 Apr 2013, 05:21 PM
Hi,

I have a rad grid but when in edit mode I need to set one of the columns default value to the selectedvalue of a combo box?  How can this be done in VB.

Thanks,

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Apr 2013, 02:56 AM
Hi,

Please try the following code snippet to set the Combobox Selected value.

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
        'the grid is in Edit mode.
        Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
        Dim combo As RadComboBox = DirectCast(item.FindControl("RadCombobox1"), RadComboBox)
        combo.SelectedValue = "your value"
    End If
End Sub

Thanks,
Princy.
0
Stefan
Top achievements
Rank 2
answered on 25 Apr 2013, 02:53 PM
Thanks Princy but I need to set the DefaultInsertValue of my grid column to the selected value of my combobox. So when I do an Add New I have this value to pass to the stored proc.

<telerik:GridBoundColumn DefaultInsertValue="??????" DataField="EmplID" DataType="System.Int32" HeaderText="Emp. ID:" ReadOnly="False" SortExpression="EmplID" UniqueName="EmplID" Visible="False">
 </telerik:GridBoundColumn>

Will this need to be javascript or can I do some kind of databinder?
0
Princy
Top achievements
Rank 2
answered on 26 Apr 2013, 04:10 AM
Hi Stefan,

I apologize for misunderstanding your requirement. One option is to set the text in GridBoundColumn(edit mode) on SelectedIndexChanged event of the RadComboBox.

ASPX:
<telerik:GridTemplateColumn>
    <EditItemTemplate>
        <telerik:RadComboBox ID="RadComboBox1" runat="server" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
            <Items>
                <telerik:RadComboBoxItem Text="NotSelected" Value="NotSelected" />
                <telerik:RadComboBoxItem Text="Car" Value="Car" />
                <telerik:RadComboBoxItem Text="Cycle" Value="Cycle" />
            </Items>
        </telerik:RadComboBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

VB:
Protected Sub RadComboBox1_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
    Dim radcombo As RadComboBox = DirectCast(sender, RadComboBox)
    Dim editItem As GridEditableItem = DirectCast(radcombo.NamingContainer, GridEditableItem)
    Dim txt As TextBox = DirectCast(editItem("UniqueNameOfBoundColumn").Controls(0), TextBox)
    If radcombo.SelectedValue = "Car" Then
        txt.Text = radcombo.SelectedValue
    End If
End Sub

Thanks,
Princy.
Tags
Grid
Asked by
Stefan
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Stefan
Top achievements
Rank 2
Share this question
or