سؤال

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?
هل كانت مفيدة؟

المحلول

Put your table inside a div with class .table_div

Your structure should be like :

<div class="table_div">
   <table> ..
</div>

نصائح أخرى

You should wrap the table in a div and apply class to that div

Working Demo

Eg:

<div class="table_div">
<table>
...
</table>
</div>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top