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

Get SelectedValue from GridDropDownColumn column

2 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Meera
Top achievements
Rank 1
Meera asked on 14 Jun 2012, 12:27 PM
Hi,

I have a RadGrid with three Levels, with a GridDropDownColumn in the second level. I would like to get the SelectedValues of the Dropdownlist for all the rows in this column in InsertCommand so that I can check wether the newly inserted column value is a duplicate entry or not.

I am able to iterate through the items in the second level of the grid and retrieve the SelectedItem.text for each row, but to be able to check for duplicate I need to compare the new SelectedValue with the existing SelectedValue.

The code I am using is given below.
GridTableView nestedView1 = (GridTableView)parentItem.ChildItem.NestedTableViews[0];
               foreach (GridDataItem childItem1 in nestedView1.Items)
               {
                   if (childItem1.OwnerTableView.Name == "Products")
                   {                        
                       string selectedText= childItem1["ProductId"].Text;
                       GridEditableItem NewItem1 = (GridEditableItem)e.Item;
                       TableCell NewProdId = NewItem1["ProductId"];
                       string NewTxtProdId = (NewProdId.Controls[0] as DropDownList).SelectedValue;           
                       string selectedValue="";
                       //Find a way to get selectedvalue of childItem1
                       if (selectedValue == NewTxtProdId)
                       {
                           DisplayMessage("This product id is already selected.");
                           e.Canceled = true;
                       }
                   }
               }

Any help is highly appreciated.

Thanks
Meera

2 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 14 Jun 2012, 01:27 PM
handle the SelectedValueChanged event of the GridDropDown column
iterate through the grid, looking at the columns of all rows except the current row
- what do you want to do if the value is already selected?
0
Meera
Top achievements
Rank 1
answered on 16 Jun 2012, 10:49 AM
Hi Marianne,

Thank you for the prompt response.

Instead of using this method I have iterated through the SqlDataSource of that detail table to check for duplicates. If the item is present I cancel the insert operation and it works.

Meera
Tags
Grid
Asked by
Meera
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Meera
Top achievements
Rank 1
Share this question
or