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

[Solved] Grid RowAction not working properly

3 Answers 199 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.
Abdulmenan
Top achievements
Rank 1
Abdulmenan asked on 21 Apr 2010, 04:19 PM
I was using Telerik Grid with RowAction method to increment an index during binding. the code is as follows

<%       int x = -1; 
             Html.Telerik() 
                   .Grid(Model.Orders) 
                   .Name("Ord") 
                   .Columns(columns => 
                       { 
                           columns.Template(o => 
                           {%> 
    <%= Html.CheckBox("Model.Orders[" + x + "].IsSelected", o.IsSelected)%> 
    <%}).Width(10); 
                           columns.Bound(o => o.ID).Title("Student Number").Width(80); 
                           columns.Bound(o => o.Name).Title("First Name").Width(150); 
 
                       }).RowAction(row => 
             { 
                 x++; 
             }) 
 
 .Sortable() 
.Render(); %> 

public class CustomerViewModel 
    { 
        public List<Order> Orders { get; set; } 
 
    } 
    public class Order 
    { 
        public int ID { get; set; } 
        public String Name { get; set; } 
        public Boolean IsSelected { get; set; } 
 
    } 
    
    public class HomeController : Controller 
    { 
        public ActionResult Index() 
        { 
            CustomerViewModel model = new CustomerViewModel() 
            { 
                Orders = new List<Order> {  
                 
                new Order() { ID = 1Name = "Banana" }, new Order() { ID = 2Name = "Onion" }, new Order(){ID=3,Name="Car"} } 
            }; 
 
            return View(model); 
        } 
    } 
public class CustomerViewModel
    {
        public List<Order> Orders { get; set; }

    }
    public class Order
    {
        public int ID { get; set; }
        public String Name { get; set; }
        public Boolean IsSelected { get; set; }

    }
   
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            CustomerViewModel model = new CustomerViewModel()
            {
                Orders = new List<Order> { 
                
                new Order() { ID = 1, Name = "Banana" }, new Order() { ID = 2, Name = "Onion" } }
            };

            return View(model);
        }
    }

in the renderd Html all check boxes are converted to input controls with same ID.  which is the last row's ID.
<input id="Model_Orders_2__IsSelected" name="Model.Orders[2].IsSelected" type="checkbox" value="true" />

it was working fine in the previous version of Telerik extension, this error comes when i upgrade from v2009 to the V2010.
can any one help me to fix this
Abdul

3 Answers, 1 is accepted

Sort by
0
Abdulmenan
Top achievements
Rank 1
answered on 26 Apr 2010, 08:05 PM
is it a bug? or do i miss anything?
Abdul

0
Accepted
Atanas Korchev
Telerik team
answered on 27 Apr 2010, 08:33 AM
Hi Abdulmenan,

Indeed we changed the way templates were rendered which seems to have affected your code. After further research I think it is the problem described in this stackoverflow thread. The solution is rather simple:
  1. Remove the RowAction delegate - you don't need it
  2. Render the checkbox like this:
    <%= Html.CheckBox("Model.Orders[" + x++ + "].IsSelected", o.IsSelected)%>



Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Abdulmenan
Top achievements
Rank 1
answered on 27 Apr 2010, 01:45 PM
Thanks a lot
Tags
Grid
Asked by
Abdulmenan
Top achievements
Rank 1
Answers by
Abdulmenan
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or