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:
I can post more the code if that is helpful and any assistance would be greatly appreciated. Thanks!
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!