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

Grid Edit Form From External Link.

2 Answers 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Francesco Vivaldi
Top achievements
Rank 1
Francesco Vivaldi asked on 18 Apr 2011, 09:12 AM
Hi I have a aspx page with a radGrid, i use edit mdoe to edit records.
when i click on a ButtobClumn of my grid i redirect user to another page "detailPage.aspx" and the page show the user detailed record.
I need to implement an EditButton in the "detailPage.aspx" to edit the current record. ? how can i do it ?

1) MainPage.aspx
     Grid -> Click on record with id 1 -> Redirect to detailPage.aspx (show detail of record 1)
2) detailPage.aspx (show detail for record 1)
     EditButton->redirect back to MainPage, with grid in edit mode for record with Id 1.

How can i implement edit button in detailPage ?

2 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 21 Apr 2011, 10:34 AM
Hello Francesco,

You can implement an edit button that will redirect back to the page containing your RadGrid. In the URL, you can add a QueryString parameter that will indicate the particular item RadGrid needs to initialize in edit mode. This URL parameter can indicate either the data key value of the record that needs to be edited, or the display index of the data item that you need to put in edit mode (the latter case if you are not using paging).

For example, if the page with your RadGrid is Default.aspx, you can have the following click handler in for the edit button in the details page:

protected void ButtonEdit_Click(object sender, EventArgs e)
{
    Response.Redirect("Default.aspx?editid=" + [item_id_here]);
}

The editid URL parameter in the above snippet indicates either the ID (a data key value) of the edited row, or the display index of the item. In the page containing RadGrid, you can check for the editid URL parameter and put the respective item in edit mode. If you are using the parameter value as a data value for the item, you can use the PreRender event of the page or the control to find the respective item and put it in edit mode. Note: rebind is required in this case:

protected void Page_PreRender(object sender, EventArgs e)
{
    if (!String.IsNullOrEmpty(Request.QueryString["editid"]))
    {
        int itemId = -1;
        if (Int32.TryParse(Request.QueryString["editid"], out itemId))
        {
            GridDataItem dataItem = RadGrid1.MasterTableView.FindItemByKeyValue("ID", itemId);
            if (dataItem != null)
            {
                dataItem.Edit = true;
                RadGrid1.Rebind();
            }
        }
    }
}


If you are using the value of the editid URL parameter as the display index of your edited item, your scenario is simplified and you can put the item in edit mode right in Page_Load without additional rebinds:

protected void Page_Load(object sender, EventArgs e)
{
    if (!String.IsNullOrEmpty(Request.QueryString["editid"]))
    {
        int itemIndex = -1;
        if (Int32.TryParse(Request.QueryString["editid"], out itemIndex))
        {
            RadGrid1.EditIndexes.Add(itemIndex);
        }
    }
}


Veli
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
Francesco Vivaldi
Top achievements
Rank 1
answered on 21 Apr 2011, 10:48 AM
Hi,
thanks, it works very well!
Tags
Grid
Asked by
Francesco Vivaldi
Top achievements
Rank 1
Answers by
Veli
Telerik team
Francesco Vivaldi
Top achievements
Rank 1
Share this question
or