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

[Solved] DropDown Selected Item

2 Answers 232 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike Sweet
Top achievements
Rank 1
Mike Sweet asked on 02 Apr 2008, 04:40 PM
Hello,

I have a grid whose editmode="forms".  In the <FormTemplate> there is a drop down list.  The list items for the drop down list are populated in the ItemCreated event and based on the value of the Item.DataItem I want to pre-select the appropriate list item.  What I have, however, does not work as the first list item is always selected.  The code for the ItemCreated event is as follows:

void OnPartAliasesItemCreated(object sender, GridItemEventArgs e)  
   {  
      if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
      {  
 
         GridEditableItem item = e.Item as GridEditableItem;  
         TextBox tbPartAlias = item.FindControl("tbPartAlias"as TextBox;  
         Label lblPartAliasValue = item.FindControl("lblPartAliasValue"as Label;  
         TextBox tbRetailList = item.FindControl("tbRetailList"as TextBox;  
         DropDownList ddlProductLine = item.FindControl("ddlProductLine"as DropDownList;  
         CheckBox cbDisplayOnRetail = item.FindControl("cbDisplayOnRetail"as CheckBox;  
         CheckBox cbRetailSpotlight = item.FindControl("cbRetailSpotlight"as CheckBox;  
         CheckBox cbDisplayOnWholesale = item.FindControl("cbDisplayOnWholesale"as CheckBox;  
         CheckBox cbListOnInfopia = item.FindControl("cbListOnInfopia"as CheckBox;  
         CheckBox cbBMWClearanceItem = item.FindControl("cbBMWClearanceItem"as CheckBox;  
         CheckBox cbSaabClearanceItem = item.FindControl("cbSaabClearanceItem"as CheckBox;  
         CheckBox cbVolvoClearanceItem = item.FindControl("cbVolvoClearanceItem"as CheckBox;  
 
         ddlProductLine.DataSource = App.Core.BusinessObjects.Part.FindAllProductLines();  
         ddlProductLine.DataBind();  
 
         if (e.Item.DataItem is App.Core.BusinessObjects.Part)  
         {  
            App.Core.BusinessObjects.Part partAlias = e.Item.DataItem as App.Core.BusinessObjects.Part;  
            lblPartAliasValue.Visible = true;  
            tbPartAlias.Visible = false;  
            lblPartAliasValue.Text = partAlias.PartAlias;  
            ddlProductLine.ClearSelection();  
            ListItem productLine = ddlProductLine.Items.FindByValue(partAlias.ProductLine);  
            if (productLine != null)  
               productLine.Selected = true;  
            cbDisplayOnRetail.Checked = partAlias.DisplayOnRetail;  
            cbRetailSpotlight.Checked = partAlias.ShowInRetailSpotLight;  
            cbDisplayOnWholesale.Checked = partAlias.DisplayOnWholeSale;  
            cbListOnInfopia.Checked = partAlias.ListOnInfopia;  
            cbBMWClearanceItem.Checked = partAlias.IsBMWClearanceItem;  
            cbSaabClearanceItem.Checked = partAlias.IsSaabClearanceItem;  
            cbVolvoClearanceItem.Checked = partAlias.IsVolvoClearanceItem;  
 
            if (!partAlias.IsAlias)  
            {  
               Label lblRetailListValue = item.FindControl("lblRetailListValue"as Label;  
               Label lblProductLineValue = item.FindControl("lblProductLineValue"as Label;  
 
               lblPartAliasValue.Visible = true;  
               tbPartAlias.Visible = false;  
               lblPartAliasValue.Text = partAlias.PartAlias;  
 
               lblRetailListValue.Visible = true;  
               tbRetailList.Visible = false;  
               lblRetailListValue.Text = partAlias.UnitPrice.ToString("c");  
 
               lblProductLineValue.Visible = true;  
               ddlProductLine.Visible = false;  
               lblProductLineValue.Text = partAlias.ProductLine;  
            }  
         }  
      }  
   } 


I can post more the code if that is helpful and any assistance would be greatly appreciated.  Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 04 Apr 2008, 05:46 AM
Hi Mike,

Please, move the code to ItemDataBound event handler and let us know how it goes. You can find more details about the differences between ItemDataBound and ItemCreated here.


Kind regards,
Ves
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike Sweet
Top achievements
Rank 1
answered on 04 Apr 2008, 03:44 PM
Thanks so much.  That solved the issue.
Tags
Grid
Asked by
Mike Sweet
Top achievements
Rank 1
Answers by
Ves
Telerik team
Mike Sweet
Top achievements
Rank 1
Share this question
or