Bind Infragistics Webdatagrid on Webdropdown change in MVC

May 20, 2011 at 5:26 AM

Hi
Thx, I am facing an issue in binding of webdatagrid on webdropdown change

My code is like this

I have a web dropdown and on change of dropdown I want to bind webdatagrid, I am doing like this and my code is as:-

Controller –For dropdown bind

 public ActionResult ActiveProjects()

        {

            var vm = new ProjectDropDownVM();

            string sOrgId = "abe";

            vm.lstProject = _projectService.GetProjectNames(sOrgId);

            return View(vm);

        }

For grid bind

public JsonResult GetData(int Id)

        {

            var vm = new ProjectDropDownVM();

            vm.lstProject = _projectService.GetProjectNames(Id);

            return this.Json(vm);

        }

View-   Code to bond drop down

<%  

        this.wcProject.DataSource = this.Model.lstProject;

        this.wcProject.DataBind();

    %>

Now on drop down change I want to bind webdatagrid, I am doing this by using client event <ClientEvents SelectionChanged="wcProject_SelectionChanged" />

<script language="javascript" type="text/javascript">

        function wcProject_SelectionChanged(sender, eventArgs) {

            // get the text/Value of the selected item

            var selectedProjecty = sender.get_selectedItem().get_text();

            var selectedProjectValue = sender.get_selectedItem().get_value();

            alert("1");

            var grid;

            var dataSource;

            var newData;

            var numRows;           

            var newData = $.getJSON("/Projects/GetData", selectedProjectValue, function (data) {

                                alert("2");

                                grid = $find('<%=WebDataGrid1.ClientID%>');

                                dataSource = grid._get_dataSource();

                                newData = JSON.parse(data.d);

 

                                var item;

                                for (var i = 0; i < newData.length; i++) {

                                    item = newData[i];

                                    $(grid.tableTemplate).render(item).appendTo(grid._elements.dataTbl.lastChild);

                                    dataSource.push(newData[i]);

                                }

                                grid._set_dataSource(dataSource);

                                grid._applyClientBinding();

                                numRows = grid.get_rows().get_length();

            });           

        }

    </script>

Plz suggest where i am wrong or we can acheive this by any other way

Regards

Shyam