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

[Solved] Grid actions can not be invoked

1 Answer 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kapil Koli
Top achievements
Rank 1
Kapil Koli asked on 17 Mar 2010, 02:16 PM
I am facing a strange problem about grid actions.

My web application simply contains a collection of web pages that renders few user controls.
This page contains telrik tab strip and each of tab contains a user control.
(My every controller action renders a view that contain user controlls embeded in tabs)

One such user control contains telerik grid. The grid has "Insert" tool button with "Edit" & "Delete" command for every row.

I have created one more user control which uses telerik menu strip. I am using this control on every page of my application.
Now everything works fine until the following code resides on the control containing menu strip. My grid actions are also working properly till then.

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    ///////////////////////////////telerik menu/////////////////////////////
</form>

But if I move this to my master page, my grid actions are not being invoked properly. Each time I am thrown to the select method of my grid. e.g. If now I chose to edit any row in grid, the Update button click takes me to the select action mentioned for the grid and not to the update action mentioned.
Things work well again if I move the form tag and script manager to the control rendering menu. But I don't want this. I want to keep this stuff on master page as it's right place.
DO I need to make any changes to invoke the right action?
Or is there anything wrong that I am doing?
Please assist.

ONE MORE QUERY-
CAN ANYONE PLEASE TELL ME HOW CAN I KNOW WHICH BUTTON IS CLICKED?
NOW MY SELECT ACTION IS BEING FIRED IRRESPECTIVE OF WHATEVER GRID BUTTON I PRESS.
I WANT TO IDENTIFY WHICH BUTTON CLICK HAS INVOKED MY SELECT ACTION METHOD.
IS THERE ANY WAY TO IDENTIFY THIS?

Thanks in advance,
Kapil

1 Answer, 1 is accepted

Sort by
0
Jack Ma
Top achievements
Rank 1
answered on 15 Apr 2010, 05:19 AM
Hi Kapil,
    Actually you can do it like this way, pass a routeValues parameter from the view to the controller. See below,
<%= Html.Telerik().Grid((IEnumerable<OrganizationCategory>)Model.OrganizationCategory)  
        .Name("OrganizationCategory")  
        .ToolBar(commands => commands.Insert())  
        .DataKeys(keys => keys.Add(c => c.ID))  
        .DataBinding(dataBinding => 
        {  
            dataBinding.Ajax()  
            .Select("DefineOrganizationCategory", "PlatformAdministration", new { ActionName = "Select" })  
            .Insert("DefineOrganizationCategory", "PlatformAdministration", new { ActionName = "Insert" })  
            .Update("DefineOrganizationCategory", "PlatformAdministration", new { ActionName = "Update" })  
            .Delete("DefineOrganizationCategory", "PlatformAdministration", new { ActionName = "Delete" });  
        })  
        .Columns(columns => 
        {  
            columns.Bound(c => c.Name).Width(130);  
            columns.Bound(c => c.Description).Width(130);  
            columns.Bound(c => c.Isvalid).Width(130);  
            columns.Command(commands => 
            {  
                commands.Edit();  
                commands.Delete();  
            }).Width(180).Title("Commands");  
        })  
        .Pageable()  
        .Sortable()  
%> 

    and in the controller,  just capture the parameter and switch with different parameter value to different actions you desired.

 

        [AcceptVerbs(HttpVerbs.Post)]  
        [GridAction]  
        public ActionResult DefineOrganizationCategory(Guid id, OrganizationCategory OrganizationCategory,string ActionName)  
        {  
            switch (ActionName)  
            {  
                case "Select":  
 
                    //return View(OrganizationCategoryRepository.All(1, 10));  
                    return View(new GridModel(OrganizationCategoryRepository.All(1, 10)));  
                case "Insert":  
                    
                    OrganizationCategoryRepository.Create(OrganizationCategory);  
                    return View(OrganizationCategoryRepository.All(1, 10));  
                case "Update":  
                    OrganizationCategoryRepository.Update(OrganizationCategory);  
                    return View(OrganizationCategoryRepository.All(1, 10));  
                case "Delete":  
                    OrganizationCategoryRepository.Delete(OrganizationCategory);  
                    return View(OrganizationCategoryRepository.All(1, 10));  
                default:  
                    break;  
 
            }  
            return View();  
        }  
 

Hope this help you.
Jack
Tags
Grid
Asked by
Kapil Koli
Top achievements
Rank 1
Answers by
Jack Ma
Top achievements
Rank 1
Share this question
or