This is a migrated thread and some comments may be shown as answers.

Add button to update/insert grid with manual updates

4 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tarkon
Top achievements
Rank 1
Tarkon asked on 18 Apr 2011, 05:47 PM
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

4 Answers, 1 is accepted

Sort by
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:
<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?
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,

foreach (GridDataItem item in grdUsers.EditItems)
{
 
    GridEditableItem editItem = (GridEditableItem)item.EditFormItem;
// item.Edit = false;
 }

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Tarkon
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tarkon
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or