问题
I have used a WebGrid
in my asp.net mvc4 application
<td >
@grid.GetHtml(tableStyle:"table_div",
headerStyle:"table_header",
columns: grid.Columns(
grid.Column("Nom de la propriété","Nom de la propriété",canSort:false,format:@<label>@Html.Raw(@item.PName)</label>),
grid.Column("Valeur de la propriété","Valeur de la propriété",canSort:false,format:@<label>@Html.Raw(@item.PName)</label>),
grid.Column("","",canSort:false,format:@<span>@{i++;<input name="proper@(@i)" type="checkbox" />}</span>)))
</td>
Css
.table_div {
overflow-y: scroll;
width: 400px;
height: 200px;
position: relative;
}
I'd like to add a vertical scrolling to my grid but it didn't work.
Generated Html
<table class="table_div">
<thead>
<tr class="table_header">
<th scope="col">
Nom de la propriété </th>
<th scope="col">
Valeur de la propriété </th>
<th scope="col">
</th>
</tr>
</thead>
<tbody>
<tr>
<td><label>poids</label></td>
<td><label>poids</label></td>
<td><span><input name="proper0" type="checkbox"></span></td>
</tr>
<tr>
<td><label>taille</label></td>
<td><label>taille</label></td>
<td><span><input name="proper1" type="checkbox"></span></td>
</tr>
</tbody>
</table>
- What is the error?
- How can i fix it?
回答1:
Put your table inside a div with class .table_div
Your structure should be like :
<div class="table_div">
<table> ..
</div>
回答2:
You should wrap the table
in a div
and apply class to that div
Working Demo
Eg:
<div class="table_div">
<table>
...
</table>
</div>
来源:https://stackoverflow.com/questions/21132847/add-a-vertical-scroll-to-a-webgrid-within-asp-net-mvc4-application