I'm fairly new to the Telerik components (by the way a great set of components) and now I have a problem retrieving data in the insertCommand method.
I have RadGrid containing a FormTemplate for editing the data.
I have RadGrid containing a FormTemplate for editing the data.
<EditFormSettings EditFormType="Template"> <FormTemplate> <div id="editdetail"> <h2> Truck information</h2> <table class="detailtable" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" style="border-collapse: collapse;"> <tr> <td class="detaillabel"> Brand: </td> <td> <asp:PlaceHolder ID="phBrandComboBox" runat="server"></asp:PlaceHolder> </td> </tr> </table> </div> </FormTemplate></EditFormSettings>
In ItemDatBound I inject a UserControle containing a Telerik ComboBox in the PlaceHolder.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyTruckItemComboBox.ascx.cs"
Inherits="Truck_marketplace.MyPortfolio.User_controls.MyTruckItemComboBox" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>MyTruckItemComboBox</title>
</head>
<body>
<telerik:RadComboBox ID="cbMyTruckItemComboBox"
OnSelectedIndexChanged="cbMyTruckItemComboBox_SelectedIndexChanged"
runat="server">
</telerik:RadComboBox>
</body>
</html>
protected void grMyTruck_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is Telerik.Web.UI.GridEditableItem && e.Item.IsInEditMode)
{
// Insert + Edit mode.
Telerik.Web.UI.GridEditableItem EditItem = (Telerik.Web.UI.GridEditableItem)e.Item;
//Brand
MyPortfolio.User_controls.MyTruckItemComboBox ComboBoxBrand = (MyPortfolio.User_controls.MyTruckItemComboBox)LoadControl("MyTruckItemComboBox.ascx");
ComboBoxBrand.ID = "cbBrand";
ComboBoxBrand.GroupID = "BRD";
ComboBoxBrand.Languagecode = "en-US";
}
if (e.Item is Telerik.Web.UI.GridEditFormInsertItem || e.Item is Telerik.Web.UI.GridDataInsertItem)
{
// Insert mode
//Brand
ComboBoxBrand.BindComboBox2();
PlaceHolder phBrandComboBox = (PlaceHolder)e.Item.FindControl("phBrandComboBox");
phBrandComboBox.Controls.Add(ComboBoxBrand);
}
}
In the InsertCommand I the try to find the ComboBox and reading the SelectedValue from it. But I dont have any luck.
All of the code in the code here fails because the cb is null.
protected void grMyTruck_InsertCommand(object sender, GridCommandEventArgs e)
{
NMHG.Data.Truck_marketplace.Advert.Advert NewAdvert = new NMHG.Data.Truck_marketplace.Advert.Advert();
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editableItem = e.Item as GridEditableItem;
UserControl userControl = editableItem.FindControl(GridEditFormItem.EditFormUserControlID) as UserControl;
Telerik.Web.UI.RadComboBox cb = userControl.FindControl("cbBrand") as Telerik.Web.UI.RadComboBox;
var temp = cb.SelectedValue;
PlaceHolder phBrandComboBox = (PlaceHolder)editableItem.FindControl("phBrandComboBox");
Telerik.Web.UI.RadComboBox cb2 = phBrandComboBox.FindControl("cbBrand") as Telerik.Web.UI.RadComboBox;
var temp2 = cb2.SelectedValue;
Telerik.Web.UI.RadComboBox cb3 = editableItem.FindControl("cbBrand") as Telerik.Web.UI.RadComboBox;
var temp3 = cb3.SelectedValue;
Telerik.Web.UI.RadComboBox cb4 = editableItem.FindControl("cbMyTruckItemComboBox") as Telerik.Web.UI.RadComboBox;
var temp4 = cb4.SelectedValue;
}
}
Can some one please help - Thanks.
I properly do some thing stupid so please bare with me ;-)
Anders Pedersen