Add button to update/insert grid with manual updates

5 posts, 0 answers
  1. Tarkon
    Tarkon avatar
    17 posts
    Member since:
    Aug 2007

    Posted 18 Apr 2011 Link to this post

    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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Apr 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tarkon
    Tarkon avatar
    17 posts
    Member since:
    Aug 2007

    Posted 20 Apr 2011 Link to this post

    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?
  5. Tarkon
    Tarkon avatar
    17 posts
    Member since:
    Aug 2007

    Posted 21 Apr 2011 Link to this post

    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.
  6. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 22 Apr 2011 Link to this post

    HI Tarkon,

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

    Thanks,
    Jayesh Goyani
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017