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

RadGrid - Open popup to edit record on page load

3 Answers 148 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 29 Jun 2011, 08:54 PM
I've got a radgrid using a modal popup edit form to edit the records. I'd like to be able to link to this page, and be able to open a specific record in edit mode (perhaps passing the id for the record in the query string).

I've found other threads mentioning doing this for the add/insert scenario. For example: http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-open-popup-add-form-on-page-load.aspx

But I want to do this for an edit/update existing record scenario.

Thanks!
-Steve

3 Answers, 1 is accepted

Sort by
0
Genti
Telerik team
answered on 05 Jul 2011, 07:40 AM
Hello Steve,

Here's a sample code that will do the job.
protected void Page_Load(object sender, EventArgs e)
{
 
    if (Request.QueryString["id"] != null)
    {
        int id = Int32.Parse(Request.QueryString["id"]);
 
        var currentPage = id / RadGrid1.PageSize;
 
        RadGrid1.MasterTableView.CurrentPageIndex = currentPage;
 
        RadGrid1.EditIndexes.Add(id % RadGrid1.PageSize);
    }
}
Note, the pager is updated accordingly depending where the item is. Otherwise, the grid would be able to put in edit mode only the items that are populated in page load.


Hope this helps.

All the best,
Genti
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Steve
Top achievements
Rank 1
answered on 05 Jul 2011, 07:40 PM
Correct me if I'm wrong, but this solution assumes that the ID's of the items being passed in are:
a) start's at 1, continues uninterrupted (2, 3, 4).
b) numeric (as opposed to alphanumeric)
c) the sort order is based on the ID, and ascending

For my scenario, issue "a" is the primary blocker for the given solution.

The solution would seem to work if there was another way of identifying the page and row that a given ID would be located.
Or, a work around could be to temporarily set paging to off while in edit mode, so all the records are displayed on the current page? This isn't ideal, especially for large data sets. And I'd still want to set paging on again after saving, so I'd still need to find what page the item is on to display that page after updating.

So, is there a solution that doesn't have the issues mentioned above?

Thanks,
-Steve  
0
Genti
Telerik team
answered on 06 Jul 2011, 12:17 PM
Hi Steve,

I could not guess what your scenario was from the description that was given.
In this case you are correct, in order to use my example you should know how to map the ids to the edit indexes beforehand.

If you could not find any way, then as you said, you're going to disable paging and crawl through all the items to find the matching id and set it to edit mode. This is a candidate solution but the efficiency in this scenario would be very low(loop through all items).

Another solution would be to set the grid data source to the row that needs to be edited. This way the searching time won't be linear(suppose you have an index on the id column in the database).

Hope this helps.

Best wishes,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Genti
Telerik team
Steve
Top achievements
Rank 1
Share this question
or