Hi!
I'm using a RadGrid with a manual code behind handler to save (update and insert) the data from the Grid Command. However, I've been asked to additionally create a button at the bottom of the form which will duplicate (not replace) these functions as well to give users more confidence. Doing it on the Command eventhandler is very easy, however I'm not sure how to perform the same functions outside of the handler. Could you give me some advice/direction on this?
Thanks!
-P
I'm using a RadGrid with a manual code behind handler to save (update and insert) the data from the Grid Command. However, I've been asked to additionally create a button at the bottom of the form which will duplicate (not replace) these functions as well to give users more confidence. Doing it on the Command eventhandler is very easy, however I'm not sure how to perform the same functions outside of the handler. Could you give me some advice/direction on this?
Thanks!
-P
4 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 19 Apr 2011, 08:30 AM
Hello Tarkon,
You can try the following code snippet to get the insert/edit row and its control from outside RadGrid.
ASPX:
C#:
Thanks,
Princy.
You can try the following code snippet to get the insert/edit row and its control from outside RadGrid.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
DataKeyNames
=
"EmployeeID"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"FirstName"
UniqueName
=
"FirstName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridEditCommandColumn
>
</
telerik:GridEditCommandColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
asp:Button
ID
=
"savebtn"
runat
=
"server"
Text
=
"Save"
OnClick
=
"savebtn_Click"
/>
<
asp:Button
ID
=
"updatebtn"
runat
=
"server"
Text
=
"Update"
OnClick
=
"updatebtn_Click"
/>
C#:
protected
void
savebtn_Click(
object
sender, EventArgs e)
{
GridEditFormInsertItem insertItem = (GridEditFormInsertItem)RadGrid1.MasterTableView.GetInsertItem();
//accessing insert row
TextBox txtname = (TextBox)insertItem[
"FirstName"
].Controls[0];
//access the controls in insert form
//insert query
}
protected
void
updatebtn_Click(
object
sender, EventArgs e)
{
int
editindex =Convert.ToInt32(RadGrid1.EditIndexes[0]);
GridEditFormItem editItem = (GridEditFormItem)RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)[editindex];
//accessing edit row
TextBox txtname = (TextBox)editItem[
"FirstName"
].Controls[0];
//access the controls in edit form
//update query
}
Thanks,
Princy.
0

Tarkon
Top achievements
Rank 1
answered on 20 Apr 2011, 03:42 PM
Thank you very much for the help! The Insert part worked great, however I'm getting an error when I try to update the form.
My error is this:
System.IndexOutOfRangeException - Index was outside the bounds of the array.
The error occurs on this line: GridEditFormItem item = (GridEditFormItem)RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)[editindex];
Any advice on this?
My error is this:
System.IndexOutOfRangeException - Index was outside the bounds of the array.
The error occurs on this line: GridEditFormItem item = (GridEditFormItem)RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)[editindex];
Any advice on this?
0

Tarkon
Top achievements
Rank 1
answered on 21 Apr 2011, 09:47 PM
Any idea what I can do to fix the System.IndexOutOfRangeException - Index was outside the bounds of the array problem? I'm being pressured to get this button put in place.
0

Jayesh Goyani
Top achievements
Rank 2
answered on 22 Apr 2011, 05:46 AM
HI Tarkon,
Thanks,
Jayesh Goyani
foreach (GridDataItem item in grdUsers.EditItems) { GridEditableItem}editItem
= (GridEditableItem)item.EditFormItem;// item.Edit = false;
Thanks,
Jayesh Goyani