Hi,
i am using radgrid and edit template. In the edit template, we are using a dropdown control to select the data which will be based on certain conditions. These conditions are dynamic and hence need to use a object datasource or direct datatable binding to the dropdown. I am trying to bind the dropdown control in the itemdatabound event (please refer to the code below), but am getting an error (please refer to the error message below) whenever I try to execute the same. Need some solution for the same.
Thanks,
Vinodh
protected void radGridItemMetal_ItemDataBound(object sender, GridItemEventArgs e)
{
try
{
foreach (GridEditableItem editItem in radGridItemMetal.MasterTableView.GetItems(GridItemType.EditFormItem))
{
if (editItem.IsInEditMode )
{
DataSet comboDataSet = items.GetComboDataset();
DataTable itemUOM = comboDataSet.Tables[0];
RadComboBox dropdownUOM = (RadComboBox)editItem.FindControl("radcomboUOM");
dropdownUOM.DataSource = itemUOM;
dropdownUOM.DataTextField = "LDValue";
dropdownUOM.DataValueField = "LDID";
dropdownUOM.DataBind();
}
}
}
catch (Exception err)
{
}
The error it gives is::
{System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
at System.Web.UI.Page.GetDataItem()
at ASP.forms_items_aspx.__DataBinding__control167(Object sender, EventArgs e) in c:\Users\Sunil\AppData\Local\Temp\Temporary ASP.NET Files\root\7864bae7\722837af\App_Web_k0euui1y.1.cs:line 0
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at Telerik.Web.UI.RadComboBox.OnDataBinding(EventArgs e)
at Telerik.Web.UI.RadComboBox.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at Telerik.Web.UI.RadComboBox.DataBind()
at MJJERP.PTL.Forms.Items.radGridItemMetal_ItemDataBound(Object sender, GridItemEventArgs e) in D:\Projects\MJJERP\Source\MJJ.PTL\Forms\Items.aspx.cs:line 120}
i am using radgrid and edit template. In the edit template, we are using a dropdown control to select the data which will be based on certain conditions. These conditions are dynamic and hence need to use a object datasource or direct datatable binding to the dropdown. I am trying to bind the dropdown control in the itemdatabound event (please refer to the code below), but am getting an error (please refer to the error message below) whenever I try to execute the same. Need some solution for the same.
Thanks,
Vinodh
protected void radGridItemMetal_ItemDataBound(object sender, GridItemEventArgs e)
{
try
{
foreach (GridEditableItem editItem in radGridItemMetal.MasterTableView.GetItems(GridItemType.EditFormItem))
{
if (editItem.IsInEditMode )
{
DataSet comboDataSet = items.GetComboDataset();
DataTable itemUOM = comboDataSet.Tables[0];
RadComboBox dropdownUOM = (RadComboBox)editItem.FindControl("radcomboUOM");
dropdownUOM.DataSource = itemUOM;
dropdownUOM.DataTextField = "LDValue";
dropdownUOM.DataValueField = "LDID";
dropdownUOM.DataBind();
}
}
}
catch (Exception err)
{
}
The error it gives is::
{System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
at System.Web.UI.Page.GetDataItem()
at ASP.forms_items_aspx.__DataBinding__control167(Object sender, EventArgs e) in c:\Users\Sunil\AppData\Local\Temp\Temporary ASP.NET Files\root\7864bae7\722837af\App_Web_k0euui1y.1.cs:line 0
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at Telerik.Web.UI.RadComboBox.OnDataBinding(EventArgs e)
at Telerik.Web.UI.RadComboBox.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at Telerik.Web.UI.RadComboBox.DataBind()
at MJJERP.PTL.Forms.Items.radGridItemMetal_ItemDataBound(Object sender, GridItemEventArgs e) in D:\Projects\MJJERP\Source\MJJ.PTL\Forms\Items.aspx.cs:line 120}