Telerik blogs

I've made small example how to use RadGrid for ASP.NET AJAX in Microsoft ASP.NET MVC:

Untitled

 

The key here is to inherit from RadGrid and call explicitly desired grid commands. Let's say you want to edit particular record:

1) Create a template column and add this to the ItemTemplate:

<%# Html.ActionLink("Edit", "RadGridCommand", new { ControlID = MyGrid1.ID, CommandName = "Edit", CommandArgument = Container.ItemIndexHierarchical }) %>

 

2) Now handle this in your controller:

public ActionResult RadGridCommand(string ControlID, string CommandName, string CommandArgument)
{
    ViewData["ControlID"] = ControlID;
    ViewData["CommandName"]= CommandName;
    ViewData["CommandArgument"] = CommandArgument;

    return View("Index");
}

 

3) Override OnPreRender in inherited class and call explicitly the grid RaisePostBackEvent() method:

protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);

    if (ViewData["ControlID"] != null && ViewData["ControlID"].ToString() == ID &&
        ViewData["CommandName"] != null)
    {
        RaisePostBackEvent(String.Format("FireCommand:{0};{1};{2}", MasterTableView.UniqueID, (string)ViewData["CommandName"], (string)ViewData["CommandArgument"]));
    }
}

For other useful techniques please refer to the attached source code.

Enjoy!

[Download]


About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks

Comments

Comments are disabled in preview mode.