4 Answers, 1 is accepted
0

Jayesh Goyani
Top achievements
Rank 2
answered on 03 Feb 2012, 05:22 PM
Hello Jocelyn,
you can get "e.Item.DataItem" only in itemDataBound event.
for update please check below code snippet.
Thanks,
Jayesh Goyani
you can get "e.Item.DataItem" only in itemDataBound event.
for update please check below code snippet.
<
MasterTableView
DataKeyNames
=
"ID"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"ID"
HeaderText
=
"ID"
UniqueName
=
"ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"Name"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblName"
runat
=
"server"
Text='<%# Eval("Name") %>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
asp:TextBox
ID
=
"txtName"
runat
=
"server"
Text='<%# Eval("Name") %>'></
asp:TextBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridEditCommandColumn
>
</
telerik:GridEditCommandColumn
>
</
Columns
>
protected
void
RadGrid1_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
GridEditableItem item = e.Item
as
GridEditableItem;
// get primary key value
string
str1 = item.GetDataKeyValue(
"ID"
).ToString();
// get bound column
string
str2 = (item[
"ID"
].Controls[0]
as
TextBox).Text;
// get control from template column
string
str3 = (item.FindControl(
"txtName"
)
as
TextBox).Text;
}
Thanks,
Jayesh Goyani
0

Jocelyn
Top achievements
Rank 1
answered on 03 Feb 2012, 06:47 PM
My Grid DataSource is a DataTable. I am trying to update things like the Demo, But when I try it I just don't update.. But I need to validate the row before updating, so i would like to be able to access to the modified row and valide it.
Here some code:
I think I wasn't clear in my first post, because I don't understand your post Jayesh.
Here some code:
<
div
class
=
"fullscreen"
>
<
telerik:RadGrid
ID
=
"gridAllergies"
runat
=
"server"
Width
=
"100%"
Skin
=
"WebBlue"
style
=
"border:0;outline:none"
Height
=
"80%"
CellSpacing
=
"0"
GridLines
=
"None"
>
<
MasterTableView
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
Visible
=
"True"
FilterControlAltText
=
"Filter RowIndicator column"
></
RowIndicatorColumn
>
<
ExpandCollapseColumn
Visible
=
"True"
FilterControlAltText
=
"Filter ExpandColumn column"
></
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridEditCommandColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
ButtonType
=
"PushButton"
EditText
=
"Modifier"
Resizable
=
"False"
>
<
HeaderStyle
Width
=
"75px"
/>
</
telerik:GridEditCommandColumn
>
<
telerik:GridBoundColumn
DataField
=
"palg_noauto"
FilterControlAltText
=
"Filter column1 column"
UniqueName
=
"column1"
Visible
=
"False"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"allergie"
FilterControlAltText
=
"Filter column2 column"
HeaderText
=
"Allergie"
SortExpression
=
"allergie"
UniqueName
=
"column2"
CurrentFilterFunction
=
"StartsWith"
FilterDelay
=
"700"
ShowFilterIcon
=
"false"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridCheckBoxColumn
DataField
=
"isGroupe"
DataType
=
"System.Boolean"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Groupe"
ReadOnly
=
"True"
UniqueName
=
"column"
ShowFilterIcon
=
"false"
AllowFiltering
=
"False"
>
</
telerik:GridCheckBoxColumn
>
<
telerik:GridBoundColumn
DataField
=
"gene_nom"
FilterControlAltText
=
"Filter column6 column"
HeaderText
=
"Groupe"
UniqueName
=
"column6"
Visible
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Date"
FilterControlAltText
=
"Filter column3 column"
HeaderText
=
"Date"
SortExpression
=
"Date"
UniqueName
=
"column3"
CurrentFilterFunction
=
"StartsWith"
FilterDelay
=
"700"
ShowFilterIcon
=
"false"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"palg_texte_1"
FilterControlAltText
=
"Filter column4 column"
SortExpression
=
"palg_texte_1"
UniqueName
=
"column4"
CurrentFilterFunction
=
"StartsWith"
FilterDelay
=
"700"
ShowFilterIcon
=
"false"
HeaderText
=
"Texte1"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"palg_texte_2"
FilterControlAltText
=
"Filter column5 column"
HeaderText
=
"Texte2"
SortExpression
=
"palg_texte_2"
UniqueName
=
"column5"
CurrentFilterFunction
=
"StartsWith"
FilterDelay
=
"700"
ShowFilterIcon
=
"false"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
UniqueName
=
"EditCommandColumn1"
FilterControlAltText
=
"Filter EditCommandColumn1 column"
></
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
</
telerik:RadGrid
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
Skin
=
"Default"
>
</
telerik:RadAjaxLoadingPanel
>
</
div
>
Protected
Sub
gridAllergies_UpdateCommand(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridCommandEventArgs)
Handles
gridAllergies.UpdateCommand
Dim
item
As
GridEditableItem = TryCast(e.Item, GridEditableItem)
Dim
allergie
As
clsAllergie =
CType
(
CType
(e.Item.DataItem, DataRowView).Row, clsAllergie)
item.UpdateValues(allergie)
allergie.Save()
End
Sub
I think I wasn't clear in my first post, because I don't understand your post Jayesh.
0

Shinu
Top achievements
Rank 2
answered on 06 Feb 2012, 05:14 AM
Hello Jocelyn,
Try the following code.
VB:
-Shinu.
Try the following code.
VB:
Protected
Sub
RadGrid1_UpdateCommand(sender
As
Object
, e
As
GridCommandEventArgs)
Dim
editItem
As
GridEditableItem = TryCast(e.Item, GridEditableItem)
Dim
newValues
As
New
Hashtable()
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem)
Dim
id
As
String
= newValues(
"UniqueName"
).ToString()
End
Sub
-Shinu.
0