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

Accessing other items in datasource

4 Answers 59 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 30 Oct 2014, 05:03 PM
I have a dropdownlist bound to a data source with 3 items, iid, cPolicyNo, GroupFundID
I need to reference both iid and groupfundid when the user selects an item.

The method I am trying to use is as below however I am getting an error:

    Error 1 Cannot convert type 'Telerik.WinControls.UI.RadListDataItem' to 'System.Data.DataRow' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion


Thanks for any help.




    private void Underwriting_Load(object sender, EventArgs e)
        {

            this.vPolicyNoForCBOTableAdapter.Fill(this.rG.vPolicyNoForCBO);

            // Load CBO Source
            this.cboPolicyNo.DataBindings.Clear();
            this.cboPolicyNo.DataSource = this.rG.vPolicyNoForCBO;
            this.cboPolicyNo.DisplayMember = "cPolicyNo";
            
            
        }

        private void cboPolicyNo_SelectedValueChanged(object sender, EventArgs e)
        {
            // TheSWShop 103014 Find Policy
            // Behavior - Allow the user to search for the Policy Number, cbo follows this behavior.
            //            In original system, once the first 3 letters are typed pull all of the related Policy Data.
            //            Get latest Year for Policy
            //            Get Group Fund

            DataRow cboPolicyRow = (this.cboPolicyNo.SelectedItem as DataRow);

            var groupfundid = cboPolicyRow["groupfundid"].ToString();

            this.groupFundID = Int32.Parse(groupfundid);

         }

4 Answers, 1 is accepted

Sort by
0
Accepted
Jeff
Top achievements
Rank 1
answered on 30 Oct 2014, 05:10 PM
You'll want to find the selected item as a radlistdataitem first, then get the databound item of that object.  Seeing as the databound item will be a view of the row, you'll want to get the DataBoundItem.Row object to return the DataRow

DataRow cboPolicyRow = (this.cboPolicyNo.SelectedItem.DataBoundItem.Row as DataRow);
0
Sam
Top achievements
Rank 1
answered on 31 Oct 2014, 12:31 PM
Jeff, 

Thanks very much for the reply, The DataBoundItem does not have the Row property.  
0
Jeff
Top achievements
Rank 1
answered on 31 Oct 2014, 12:39 PM
It'll just be returned to you as a generic object - you'll probably need to define a conversion to a DataRowView
0
Sam
Top achievements
Rank 1
answered on 31 Oct 2014, 02:25 PM
Jeff, Thanks very much for the assistance - That worked.



DataRowView cboPolicyRow = (this.cboPolicyNo.SelectedItem.DataBoundItem as DataRowView);

 var groupfundid = cboPolicyRow.Row.ItemArray[2];
Tags
DropDownList
Asked by
Sam
Top achievements
Rank 1
Answers by
Jeff
Top achievements
Rank 1
Sam
Top achievements
Rank 1
Share this question
or