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

How to get selected value from dropdown for insertCommand

3 Answers 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vincent bui
Top achievements
Rank 1
vincent bui asked on 14 Jan 2010, 04:52 AM

Please help me on this since I am new.  Thanks a lot.

I changed the text box to a dropdown as below:

from

        <telerik:GridBoundColumn DataField="name" DefaultInsertValue=""
            HeaderText="name" SortExpression="name" UniqueName="name">
        </telerik:GridBoundColumn>

to
        <telerik:GridDropDownColumn DatasourceID=sqldatasource2 ListValueField=name ListTextField=name
            EnableEmptyListItem=true EmptyListItemText="choose an option" DataField="name"
            datatype=System.String
            HeaderText="name" SortExpression="name" UniqueName="name">
        </telerik:GridDropDownColumn>

the statement below from insertCommand event handler failed since I don't know how to get the selected value from the dropdown

Dim CompanyName As String = TryCast(newItem("name").Controls(0), TextBox).Text

Please help me.
---------------------------------------------------------------------------------------------------------------------

[VB] InsertCommand event handler

'Get the GridEditableItem of the RadGrid

Dim

newItem

 

As GridEditableItem = TryCast(e.Item, GridEditableItem)

 

'Access the textbox from the edit form template and store the values in string variables.

Dim

 

 

CompanyName As String = TryCast(newItem("CompanyName").Controls(0), TextBox).Text

 

Dim

 

 

Phone As String = TryCast(newItem("Phone").Controls(0), TextBox).Text

 

Try

'Insert Query execution

SqlDataSource1.InsertCommand =

 

"INSERT INTO Shippers (CompanyName, Phone) Values ('" +

 

CompanyName +

 

"','" + Phone + "')"

 

SqlDataSource1.Insert()

Catch

 

 

ex As Exception

 

RadGrid1.Controls.Add(

 

New LiteralControl("Unable to insert Shipper. Reason: " +

 

ex.Message))

e.Canceled =

 

True

 

End Try
--------------------------------------------------------
 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Jan 2010, 05:41 AM
Hello Vincent,

For a GridDropDownColumn, the control rendered during insert mode would be a RadComboBox by default. So you have to access the RadComboBox as shown below:

vb:
Dim newItem As GridEditableItem = TryCast(e.Item, GridEditableItem) 
 
Dim CompanyName As String = (TryCast(newItem("name").Controls(0), RadComboBox)).SelectedItem.Text 

-Princy.
0
vincent bui
Top achievements
Rank 1
answered on 15 Jan 2010, 05:09 AM
Princy,
Thank you very much for your help.

Actually I had it like
Dim CompanyName As String = (TryCast(newItem("name").Controls(0), RadComboBox)).SelectedItem.Value

after looking at your help code below
Dim CompanyName As String = (TryCast(newItem("name").Controls(0), RadComboBox)).SelectedItem.Text

I would definitely recommend the company to buy this product.

VB
0
Supriya
Top achievements
Rank 1
answered on 28 Sep 2012, 02:07 PM
Thanks alot.. That helped!!
Tags
Grid
Asked by
vincent bui
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
vincent bui
Top achievements
Rank 1
Supriya
Top achievements
Rank 1
Share this question
or