开发者

ASP.NET MVC3 Webgrid with two rows per record

开发者 https://www.devze.com 2023-04-03 23:35 出处:网络
I\'m having trouble presenting data through WebGrid with two rows for each record. My data should be presented in a tabular format, but because there are too many colum开发者_Python百科ns and one of

I'm having trouble presenting data through WebGrid with two rows for each record.

My data should be presented in a tabular format, but because there are too many colum开发者_Python百科ns and one of the column actually have too much data (complete address) I want to display them in two rows for each record.

Any idea on how I can accomplish this? Thank you.

A simple example of the table mark up that I want to see for each record is:

<tr>
<td>
    123456
</td>
<td>
    string
</td>
<td>
    string
</td>
<td>
    <input type="checkbox" name="ProductIds" value="1">
</td>
</tr>
<tr>
<td colspan="4">
    <div>
    </div>
</td>
</tr>


<tr><td>
<table>
<tr>
<td>123456</td>
<td>string</td>
<td>string</td>
<td><input type="checkbox" name="ProductIds" value="1" /></td>
</tr>
<tr><td colspan="4">http://link</td></tr>
</table>
</td></tr>


I would create a grid with only one column. Then, use the fact that format, the second parameter of the grid.Column, is of type Func. Therefore, you can use this to create a new HtmlString:

grid.Column("AnyOldColumnName", format: item => new HtmlString(// Code to render a table with two rows))

Ie, use the item parameter in the lambda function to render a table with two columns.

I have never done this, and have no idea what kind of performance it would have. But I think that is the best bet.


@grid.GetHtml(tableStyle: "webgrid1", columns: grid.Columns(grid.Column(grid.Column(format: item => new HtmlString("<table>"+
                                      "<tr>"+ "<td>"+@lblField1+"</td>"+"<td>"+@lblField2+"</td>"+"<td>"+@lblField3+"</td>"                                                                        
                                      +"</tr>" +"<tr>"+ "<td>"+@item.Field1+"</td>"+"<td>"+@item.Field2+"</td>"
                                      +"<td>"+@item.Field3+"</td>" +"</tr>" +"<tr>"+ "<td>"+@lblField4+"</td>"
                                      +"<td>"+@lblField5+"</td>" +"<td>"+@lblField6+"</td>" +"</tr>"+"<tr>"+
                                      "<td>"+"</td>"+ "<td>"+@item.Field4+"</td>" +"<td>"+@item.Field5+"</td>"
                                      +"<td>"+@item.Field6+"</td>" +"</tr>" +"</table>"))))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号