Hello,
After editing a record and the update I get two records.
After the UpdateCommand, I get the old record and a new record in the database. Where is my mistake?
Reiner
After editing a record and the update I get two records.
<
telerik:RadGrid
ID
=
"RadGrid2"
runat
=
"server"
AutoGenerateColumns
=
"False"
CellSpacing
=
"0"
Culture
=
"de-DE"
DataSourceID
=
"ObjectDataSource2"
GridLines
=
"None"
AllowPaging
=
"True"
AllowSorting
=
"True"
AllowMultiRowEdit
=
"false"
oninsertcommand
=
"RadGrid2_InsertCommand"
onitemdatabound
=
"RadGrid2_ItemDataBound"
onupdatecommand
=
"RadGrid2_UpdateCommand"
>
<
ClientSettings
>
<
Selecting
CellSelectionMode
=
"None"
/>
</
ClientSettings
>
<
MasterTableView
AllowAutomaticDeletes
=
"True"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
CommandItemDisplay
=
"TopAndBottom"
DataKeyNames
=
"TypeID"
DataSourceID
=
"ObjectDataSource2"
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
/>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
Visible
=
"True"
>
<
HeaderStyle
Width
=
"20px"
/>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
Visible
=
"True"
>
<
HeaderStyle
Width
=
"20px"
/>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"TypeID"
DataType
=
"System.Int64"
FilterControlAltText
=
"Filter TypeID column"
HeaderText
=
"TypeID"
ReadOnly
=
"True"
UniqueName
=
"TypeID"
Visible
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
DataField
=
"TypeName"
FilterControlAltText
=
"Filter TypeName column"
HeaderText
=
"TypeName"
SortExpression
=
"TypeName"
UniqueName
=
"TypeName"
>
<
EditItemTemplate
>
<
asp:TextBox
ID
=
"TypeNameTextBox"
runat
=
"server"
Text='<%# Bind("TypeName") %>'></
asp:TextBox
>
<
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator3"
runat
=
"server"
ControlToValidate
=
"TypeNameTextBox"
Display
=
"Dynamic"
ErrorMessage="<%$ Resources:BasicSettings, RequiredValidation %>"></
asp:RequiredFieldValidator
>
</
EditItemTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"TypeNameLabel"
runat
=
"server"
Text='<%# Eval("TypeName") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"TypeText"
FilterControlAltText
=
"Filter TypeText column"
HeaderText
=
"TypeText"
SortExpression
=
"TypeText"
UniqueName
=
"TypeText"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
DataField
=
"TypeObjectTypes"
FilterControlAltText
=
"Filter TypeObjectTypes column"
HeaderText
=
"Object Type"
UniqueName
=
"TypeObjectTypes"
>
<
EditItemTemplate
>
<
asp:CheckBoxList
ID
=
"CblObjectTypes"
runat
=
"server"
>
<
asp:ListItem
Value
=
"DynamicImage"
>Dynamic Image</
asp:ListItem
>
<
asp:ListItem
Value
=
"StaticURL"
>Static URL</
asp:ListItem
>
<
asp:ListItem
>Static Text</
asp:ListItem
>
<
asp:ListItem
Value
=
"DynamicScrolltext"
>Dynamic Scrolltext</
asp:ListItem
>
<
asp:ListItem
Value
=
"FreeText"
>Free Text</
asp:ListItem
>
<
asp:ListItem
>Object List</
asp:ListItem
>
</
asp:CheckBoxList
>
</
EditItemTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"TypeObjectTypesLabel"
runat
=
"server"
Text='<%# Eval("TypeObjectTypes") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"TypeMenu"
FilterControlAltText
=
"Filter TypeMenu column"
HeaderText
=
"Menu Text"
UniqueName
=
"TypeMenu"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
DataField
=
"TypePriority"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter TypePriority column"
HeaderText
=
"Priority"
UniqueName
=
"TypePriority"
>
<
EditItemTemplate
>
<
asp:TextBox
ID
=
"TypePriorityTextBox"
runat
=
"server"
Text='<%# Bind("TypePriority") %>'></
asp:TextBox
>
</
EditItemTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"TypePriorityLabel"
runat
=
"server"
Text='<%# Eval("TypePriority") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"ProjectID"
DataType
=
"System.Int64"
FilterControlAltText
=
"Filter ProjectID column"
HeaderText
=
"Project"
UniqueName
=
"ProjectID"
Visible
=
"False"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
FilterControlAltText
=
"Filter EditCommandColumn column"
HeaderText="<%$ Resources:BasicSettings, Edit %>">
</
telerik:GridEditCommandColumn
>
<
telerik:GridButtonColumn
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
ConfirmText="<%$ Resources:BasicSettings, ConfirmDelete %>"
HeaderText="<%$ Resources:BasicSettings, Delete %>" Text="Delete"
UniqueName="DeleteColumn">
</
telerik:GridButtonColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
>
</
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
>
</
FilterMenu
>
</
telerik:RadGrid
>
<
asp:ObjectDataSource
ID
=
"ObjectDataSource2"
runat
=
"server"
DeleteMethod
=
"DeleteLayoutType"
InsertMethod
=
"InsertLayoutType"
SelectMethod
=
"GetLayoutTypes"
TypeName
=
"LayoutTypesBLL"
UpdateMethod
=
"UpdateLayoutType"
>
<
DeleteParameters
>
<
asp:Parameter
Name
=
"TypeID"
Type
=
"Int32"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"TypeName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"TypeText"
Type
=
"String"
/>
<%--<
asp:Parameter
Name
=
"TypeObjectTypes"
Type
=
"String"
/>--%>
<
asp:Parameter
Name
=
"TypeMenu"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"TypePriority"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"ProjectID"
Type
=
"Int64"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"TypeName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"TypeText"
Type
=
"String"
/>
<%--<
asp:Parameter
Name
=
"TypeObjectTypes"
Type
=
"String"
/>--%>
<
asp:Parameter
Name
=
"TypeMenu"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"TypePriority"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"ProjectID"
Type
=
"Int64"
/>
<
asp:Parameter
Name
=
"TypeID"
Type
=
"Int32"
/>
</
UpdateParameters
>
</
asp:ObjectDataSource
>
protected
void
RadGrid2_InsertCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
CheckBoxList cb = (CheckBoxList)item.FindControl(
"CblObjectTypes"
);
string
selecteditems =
""
;
for
(
int
i = 0; i < cb.Items.Count; i++)
{
if
(cb.Items[i].Selected)
selecteditems += cb.Items[i].Value +
","
;
}
if
(selecteditems !=
""
)
{
if
(selecteditems.EndsWith(
","
))
{
int
lastdel = selecteditems.LastIndexOf(
","
);
selecteditems = selecteditems.Remove(lastdel);
}
}
ObjectDataSource2.InsertParameters.Add(
"TypeObjectTypes"
, selecteditems);
}
}
protected
void
RadGrid2_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
CheckBoxList cb = (CheckBoxList)item.FindControl(
"CblObjectTypes"
);
string
[] items;
if
(e.Item.OwnerTableView.IsItemInserted)
{
//item is about to be inserted
items =
new
string
[] {
""
};
}
else
{
//item is about to be edited
items = (e.Item.DataItem
as
DataRowView)[
"TypeObjectTypes"
].ToString().Split(
new
char
[] {
','
});
}
for
(
int
i = 0; i < cb.Items.Count; i++)
{
if
(items.Contains(cb.Items[i].Value))
cb.Items[i].Selected =
true
;
}
}
}
protected
void
RadGrid2_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
CheckBoxList cb = (CheckBoxList)item.FindControl(
"CblObjectTypes"
);
string
selecteditems =
""
;
for
(
int
i = 0; i < cb.Items.Count; i++)
{
if
(cb.Items[i].Selected)
selecteditems += cb.Items[i].Value +
","
;
}
if
(selecteditems !=
""
)
{
if
(selecteditems.EndsWith(
","
))
{
int
lastdel = selecteditems.LastIndexOf(
","
);
selecteditems = selecteditems.Remove(lastdel);
}
}
ObjectDataSource2.UpdateParameters.Add(
"TypeObjectTypes"
, selecteditems);
}
}
After the UpdateCommand, I get the old record and a new record in the database. Where is my mistake?
Reiner