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

I need the selected value from a ComboBox control in a RadGrid in insert mode

6 Answers 530 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rolf
Top achievements
Rank 1
Rolf asked on 31 Jan 2011, 02:27 PM
I need the selected value from a ComboBox control in a RadGrid in insert mode (Edit mode = popup) Immediately after selecting by the user and before an insert into the database.

I set ComboBoxControl to AutoPostBack.

With:

Sub RadGrid_ItemCreated (....)
Dim item As GridEditableItem = TryCast (e.Item, GridEditableItem)
Dim editor As GridView DropDownList column editor = DirectCast (item.EditManager.GetColumnEditor ("field"), grid column drop down editor)
editor.ComboBoxControl.AutoPostBack = True
Dim myValue As String = editor.ComboBoxControl.SelectedValue

With myValue I just get the "old" value and not the new selected value from user. The new value will appear only after another postback. Is there a solution?

Is it possible for the selected value from a ComboBox control in insert mode (not edit mode) to get outside of sub RadGrid_ItemCreated (....)?

Thanks
Rolf from Switzerland

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Feb 2011, 06:25 AM
Hello Rolf,

You can access the SelectedValue in 'SelectedIndexChanged' event of RadComboBox . Following is a sample code which shows how to get the selected value of RadComboBox(in insert mode) and set that value to a Textbox in insert form. Hope this helps.

ASPX:
<MasterTableView CommandItemDisplay="Top"  EditMode="PopUp">
    <Columns>
        <telerik:GridDropDownColumn UniqueName="GridDropDownColumn"
           DataSourceID="SqlDataSource1"
            ListTextField="FirstName" ListValueField="FirstName">
        </telerik:GridDropDownColumn>
        <telerik:GridBoundColumn DataField="FirstName"  UniqueName="FirstName">
        </telerik:GridBoundColumn>
       </Columns>
</MasterTableView>

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
        {
            GridEditFormInsertItem inserItem = (GridEditFormInsertItem)e.Item;
            RadComboBox combo = (RadComboBox)inserItem["GridDropDownColumn"].Controls[0];
            combo.AutoPostBack = true;
            combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged);
//attaching 'SelectedIndexChanged' event to GridDropDownColumn
        }
    }
 
    void combo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox combo = (RadComboBox)o;
        string value = combo.SelectedValue; //getting selectedVaue
        GridEditFormInsertItem inserItem=(GridEditFormInsertItem)combo.NamingContainer;
        TextBox txtbox = (TextBox)inserItem["FirstName"].Controls[0];
        txtbox.Text = value;
    }

Thanks,
Princy.
0
Rolf
Top achievements
Rank 1
answered on 01 Feb 2011, 12:54 PM
Thanks Princy,
Super. It works very well. Thank you.

Now I have another problem. I want to hide a second RadComboBox in the grid with the value.
If Value = "9" Then RadComboBox2.Visible = True
If Value = "0 " Then RadComboBox2.Visible = False

Again, I get no further.
How do I write this in the 'Private Sub combo_SelectedIndexChanged (....)'?

Rolf
0
Princy
Top achievements
Rank 2
answered on 02 Feb 2011, 06:05 AM
Hello Rolf,

I guess your second RadComboBox is a GridDropDownColumn. If so you can access it using its UniqueName in SelectedIndexChanged event of first combobox .

ASPX:
<Columns>
   <telerik:GridDropDownColumn UniqueName="GridDropDownColumn" DataSourceID="SqlDataSource1"
        ListTextField="FirstName" ListValueField="FirstName">
    </telerik:GridDropDownColumn>
    <telerik:GridDropDownColumn UniqueName="GridDropDownColumn2" >
    </telerik:GridDropDownColumn>
</Columns>

VB.NET:
Private Sub combo_SelectedIndexChanged(o As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
    Dim combo As RadComboBox = DirectCast(o, RadComboBox)
    Dim value As String = combo.SelectedValue
    Dim inserItem As GridEditFormInsertItem = DirectCast(combo.NamingContainer, GridEditFormInsertItem)
    If value = "0" Then
        Dim combo2 As RadComboBox = DirectCast(inserItem("GridDropDownColumn2").Controls(0), RadComboBox)
        combo2.Visible = False
    End If
End Sub

Thanks,
Princy.
0
Rolf
Top achievements
Rank 1
answered on 02 Feb 2011, 09:01 AM
Hello Princy,
Once again, super. It works very well.
Thanks and Regards Rolf
0
mani
Top achievements
Rank 1
answered on 29 Jul 2011, 09:06 AM

ASPX:
<MasterTableView CommandItemDisplay="Top"  EditMode="PopUp">
    <Columns>
        <telerik:GridDropDownColumn UniqueName="GridDropDownColumn"
           DataSourceID="SqlDataSource1"
            ListTextField="FirstName" ListValueField="FirstName">
        </telerik:GridDropDownColumn>
        <telerik:GridBoundColumn DataField="FirstName"  UniqueName="FirstName">
        </telerik:GridBoundColumn>
       </Columns>
</MasterTableView>

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
        {
            GridEditFormInsertItem inserItem = (GridEditFormInsertItem)e.Item;
            RadComboBox combo = (RadComboBox)inserItem["GridDropDownColumn"].Controls[0];
            combo.AutoPostBack = true;
            combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged);
//attaching 'SelectedIndexChanged' event to GridDropDownColumn
        }
    }
 
    void combo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox combo = (RadComboBox)o;
        string value = combo.SelectedValue; //getting selectedVaue
        GridEditFormInsertItem inserItem=(GridEditFormInsertItem)combo.NamingContainer;
        TextBox txtbox = (TextBox)inserItem["FirstName"].Controls[0];
        txtbox.Text = value;
    }


Nice Code,

Thanks,
Princy.
0
Clive Hoggar
Top achievements
Rank 1
answered on 09 Nov 2011, 07:22 PM
Hi Shinu

I know this is over a year old, but I am having trouble with it.
First off I am using the telerik converter to get it into vb.
The visual studio 2010 intellisense informs me that the line

combo.SelectedIndexChanged += New RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged)


is not allowed because SelectedIndexChanged is an event and cannot be called directly.

How can I get round this?

Thanks

Clive

Q32010 radajax controls, asp.net 4.0
Tags
Grid
Asked by
Rolf
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rolf
Top achievements
Rank 1
mani
Top achievements
Rank 1
Clive Hoggar
Top achievements
Rank 1
Share this question
or