Add a vertical scroll to a webgrid within Asp.net mvc4 application

青春壹個敷衍的年華 提交于 2020-01-06 15:29:11

问题


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>
  1. What is the error?
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!