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

Get RadComboBox Attribute in RadGrid

3 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ajay
Top achievements
Rank 1
Ajay asked on 02 Dec 2011, 04:58 PM
Hi

I have a RadComboBox in RadGrid.

How do I get the Attribute of the RadCombo box. I have tired the following code but I get an error :

    Protected Sub rcbPortList_Grid_SelectedIndexChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
 
        Dim rcbPortList_Grid As RadComboBox = New RadComboBox
        rcbPortList_Grid = DirectCast(sender, RadComboBox)
 
        Dim EditedItem As GridDataItem = DirectCast(rcbPortList_Grid.NamingContainer, GridDataItem)
        Dim gvddlEmployee As RadComboBox = DirectCast(EditedItem.FindControl("rcbPortList_Grid "), RadComboBox)
 
        Dim rtxtLongDegree_Grid As RadNumericTextBox = DirectCast(EditedItem.FindControl("rtxtLongDegree_Grid"), RadNumericTextBox)
        Dim rtxtLongMin_Grid As RadNumericTextBox = DirectCast(EditedItem.FindControl("rtxtLongMin_Grid "), RadNumericTextBox)
        Dim rtxtLongSec_Grid As RadNumericTextBox = DirectCast(EditedItem.FindControl("rtxtLongSec_Grid "), RadNumericTextBox)
 ' Object reference not set to an instance of an object. error at line below
        rtxtLongDegree_Grid.Text = rcbPortList_Grid.SelectedItem.Attributes(0)("Longitude")
 
end if

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 07 Dec 2011, 08:10 AM
Hi Ajay,

At which line are you getting an error and what is it?

Two things that I notice:
1) This code will work only for InPlace edit mode. If you use EditForms or PopUp edit mode, you need to cast the combo's naming container to GridEditableItem/GridEditFormItem.
2) You index the Attributes both by numeric index and by key. You should only use a key in order to access an Attribute of a control, e.g. combo.SelectedItem.Attributes("onclick"). Also, I assume that Longitude is an attribute which you have assigned in a previos event?

Kind regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Ajay
Top achievements
Rank 1
answered on 07 Dec 2011, 10:27 AM
I am getting the error at:

rtxtLongDegree_Grid.Text = rcbPortList_Grid.SelectedItem.Attributes(0)(
"Longitude")


I am using Inline Edit and yes the attribute "Longitude" is added before hand..
0
Tsvetina
Telerik team
answered on 07 Dec 2011, 01:51 PM
Hi Ajay,

Have you tried accessing the Attribute only by key:
string attribute = combo.SelectedItem.Attributes("Longitude")

I am not sure exactly what indexing is done using the numeric indexer.

All the best,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Ajay
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Ajay
Top achievements
Rank 1
Share this question
or