Hi,
I create a server control that inherits the grid, I create the templatecolumn dinamically with ItemTemplate and EditItemTemplate
The code that create the MyTemplateText is:
I use entity framework with automatic insert/update/delete.
Insert and Update operations works fine, but Delete NOT ! , the entity tells me a concurrency message ... but it's a false messagge.
Because doing a debug after the "DeleteComand" the grid "executes" public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control pContainer) " the grid know the DAtaKeyName and it's the one i choose to delete, but on this function i see the return the LAST ITEM of the page i'm watching on the grid.
Then The entity Class receive a bad information...
So, the question is where is the mistake, ??? I try a telerik standar grid with automatic CRUD operations with entity datasource and everything works as expected, the entity class received information ok.
I hope someone undertand my problem.
Thanks !!!!
I create a server control that inherits the grid, I create the templatecolumn dinamically with ItemTemplate and EditItemTemplate
AutoPostBackOnFilter = true;
CurrentFilterFunction = Telerik.Web.UI.GridKnownFunction.Contains;
ShowFilterIcon = false;
HeaderStyle.Width = _width;
ItemStyle.Width = _width;
ItemStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
HeaderTemplate = new MyHeaderTemplate(_type, DataField, _width.Value - CommonParameters.GridFilterWidthDistances, LabelText);
ItemTemplate = new MyTemplateText(new GridTemplateColumnParameter()
.SetColumnType(CommonParameters.RadGridTemplateColumnType.ItemTemplate)
.SetDataField(DataField)
.SetDataFieldItem(DataFieldItem)
.SetWidth(_width.Value - CommonParameters.GridFilterWidthDistances)
.SetReadOnlyOn(_readOnlyOn)
);
EditItemTemplate = new MyTemplateText(new GridTemplateColumnParameter()
.SetColumnType(CommonParameters.RadGridTemplateColumnType.EditItemTemplate)
.SetDataField(DataField)
.SetDataFieldItem(DataFieldItem)
.SetWidth(_width.Value - CommonParameters.GridFilterWidthDistances)
.SetReadOnlyOn(_readOnlyOn)
.SetRequired(_required)
.SetCodice(_codice)
.SetMaxLength(_maxLength)
.SetLabelText(LabelText)
);
The code that create the MyTemplateText is:
private class MyTemplateText : IBindableTemplate
{
private TextBox _txb;
private Label _lbl;
private GridTemplateColumnParameter _gtcp;
public MyTemplateText(GridTemplateColumnParameter pGtcp)
{ // Parametert to create label ant text box of the template column
_gtcp = pGtcp;
}
#region IBindableTemplate Members
public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control pContainer)
{
OrderedDictionary data = new OrderedDictionary();
switch (_gtcp.ColumnType)
{
case CommonParameters.RadGridTemplateColumnType.ItemTemplate:
data.Add(_gtcp.DataField, _lbl.Text);
break;
case CommonParameters.RadGridTemplateColumnType.EditItemTemplate: data.Add(_gtcp.DataField, _txb.Text); break;
}
return data;
}
#endregion
#region ITemplate Members
public void InstantiateIn(System.Web.UI.Control pContainer)
{
switch (_gtcp.ColumnType)
{
case CommonParameters.RadGridTemplateColumnType.ItemTemplate:
{
_lbl = new Label();
_lbl.CssClass = "ColumnText";
_lbl.Width = new System.Web.UI.WebControls.Unit(_gtcp.Width);
_lbl.ParentType = CommonParameters.BloccoParentType.RadGrid;
_lbl.DataBinding += new EventHandler(Lbl_DataBinding);
pContainer.Controls.Add(_lbl);
}
break;
case CommonParameters.RadGridTemplateColumnType.EditItemTemplate:
{
_txb = new TextBox();
_txb.ID = "txb" + _gtcp.DataField;
_txb.Width = new System.Web.UI.WebControls.Unit(_gtcp.Width);
_txb.DataBinding += new EventHandler(Txb_DataBinding);
_txb.MaxLength = _gtcp.MaxLength;
switch (_gtcp.ReadOnlyOn)
{
case CommonParameters.ReadOnlyTemplateMode.All:
{
_txb.ReadOnly = true;
} break;
case CommonParameters.ReadOnlyTemplateMode.Item:
{
} break;
default: throw new NotImplementedException("ReadOnlyOn non ancora gestita in tutte le tipologie");
}
pContainer.Controls.Add(_txb);
if (_gtcp.Required)
{
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = "rfv" + _gtcp.DataField;
rfv.CssClass = "ValidatorStyle";
rfv.ControlToValidate = "txb" + _gtcp.DataField;
rfv.Text = "!";
rfv.ErrorMessage = _gtcp.LabelText + " è obbligatorio!";
rfv.Display = ValidatorDisplay.Static;
pContainer.Controls.Add(rfv);
}
if (_gtcp.Codice)
{
RegularExpressionValidator rev = new RegularExpressionValidator();
rev.ID = "rev" + _gtcp.DataField;
rev.ControlToValidate = "txb" + _gtcp.DataField;
rev.Text = "!";
rev.CssClass = "ValidatorStyle";
rev.ErrorMessage = _gtcp.LabelText + " contiene caratteri non validi!";
rev.Display = ValidatorDisplay.Static;
rev.ValidationExpression = "^[^\\/*?\"<>|]*$";
pContainer.Controls.Add(rev);
}
} break;
}
}
void Lbl_DataBinding(object sender, EventArgs e)
{
Telerik.Web.UI.GridDataItem item = _lbl.NamingContainer as Telerik.Web.UI.GridDataItem;
if (DataBinder.Eval(item.DataItem, _gtcp.DataField) != null)
{
_lbl.Text = DataBinder.Eval(item.DataItem, _gtcp.DataField).ToString();
}
}
void Txb_DataBinding(object sender, EventArgs e)
{
Telerik.Web.UI.GridItem item = _txb.NamingContainer as Telerik.Web.UI.GridItem;
if (item is Telerik.Web.UI.GridDataItem)
{
object value = DataBinder.Eval(item.DataItem, _gtcp.DataField);
if ((value != DBNull.Value) && (value != null))
{
_txb.Text = value.ToString();
}
else
{
_txb.Text = "";
}
}
}
#endregion
}
I use entity framework with automatic insert/update/delete.
Insert and Update operations works fine, but Delete NOT ! , the entity tells me a concurrency message ... but it's a false messagge.
Because doing a debug after the "DeleteComand" the grid "executes" public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control pContainer) " the grid know the DAtaKeyName and it's the one i choose to delete, but on this function i see the return the LAST ITEM of the page i'm watching on the grid.
Then The entity Class receive a bad information...
So, the question is where is the mistake, ??? I try a telerik standar grid with automatic CRUD operations with entity datasource and everything works as expected, the entity class received information ok.
I hope someone undertand my problem.
Thanks !!!!