In my ASP.NET MVC 2.0 project, I have a user control that loops through the Model data and displays multiple rows. Here is the code:
<div id="DivMain">
<%
var index = 0;
foreach (var item in Model)
{ %>
<div data_id="<%= item.Id %>" onclick="page.toggleId(<%= item.Id %>)">
<div style="display:none">
<%= Html.Encode(item.Id)%>
</div>
<div>
<%= 开发者_StackOverflow中文版Html.Encode(item.Question)%>
</div>
</div>
<%
index++;
} %>
</div>
I want the item.Name column to display a master/slave relationship. example - Question1(Question column on the first row) should display a + sign next to it. Clicking on the + sign should list all the Answers associated with that Question. Basically the model data has a one to many relationship between Question and Answers.
How can this be achieved?
Take a look at the Telerik mvc controls, the grid there is fairly easy to use for scenarios like this. And it's free if you do not need support. Samples can be found here.
精彩评论