Make dynamically generate table stay in form when not enough item in row

I am working with asp.net MVC. I have dynamically generate table with 5 items in a row on my view. But I have a problem when model have not enough 5 items, items width will increase to fill in row like below:

| x | x | x | x | x | (when have >=5 item) | x | x | (when have <5 item, in this case is 2) | x | x | (what I want to display)

This is my cshtml code:

<table style="width:100%;height:100%"> @{ int count = 0; foreach (var thread in Model) { if (count % 5 == 0) { @:<tr> } <td style="width:20%"> //thread details here </td> count++; if (count % 5 == 0) { @:</tr> } } } </table>

I can change to 2 items per row or use fix width in , but it is not my goal. Can you suggest me some way to improve my table?

--------------Solutions-------------

I solved it by add more blank <td> in row if my items smaller than 5. Now it display like I want

<table style="width:100%;height:100%">
@{
int count = 0;
foreach (var thread in Model)
{
if (count % 5 == 0)
{
@:<tr>
}
<td style="width:20%">
//thread details here
</td>
count++;
if (count % 5 == 0)
{
@:</tr>
}
}
while (count%5!=0)
{
<td></td>
count++;
}
@:</tr>
}
</table>

Category:html Time:2018-08-05 Views:0

Related post

  • Android, Make dynamically generated table rows clickable 2012-04-18

    I am trying to show a dialog on the click of my table row.My table rows are dynamically generated, having 3 columns.1 ImageView and 2 TextViews. My table rows are generated by this loop for (i = 0; i < name.length; i++) { tr = new TableRow(this);

  • How to dynamically generate table column definitions in SQL Server 2008 function 2009-05-13

    IN SQL Server 2008 I have a situation where I need to return a dynamically generated table, and the columns are also dynamically generated. Everything in this was generated by queries, as I started with one id, then I get the column names and types,

  • How to automaticaly print a form when a new item is posted to a list in SharePoint? 2009-07-24

    How to automaticaly print a form when a new item is posted to a list in SharePoint? I created a list in SP, with customized Entry and Edit forms and a workflow that connects them. Everytime a new item is posted the Entry form needs to be used, but wh

  • I need help passing data to an modal popup iframe from a dynamically generated table 2010-11-07

    I am using php to dynamically generate a table of information from a mysql database. Each row of data has an edit button. When I click edit, I want to popup a modal iframe containing a form for editing the data. I have the table and the popup working

  • Android dynamically generating tables 2010-11-17

    I have an android activity which has a header, some title text, and then I want to dynamically generate a given number of tables. In addition, I want to be able to scroll down to view all of the tables on the activity (not scroll the individual table

  • jQuery and dynamically generated table from a start and finish value 2010-12-06

    I'd like to use a slider on a html form using jQuery. The slider needs values from 00:00 and 23:55 and have to handles on it for start and finish times. From the two values generated from the slide a table needs to be generated (I assume with some ki

  • How to use HSQLDB to dynamically generate tables for JDBC application 2011-07-14

    I want to use HyperSQL as an in-memory database for integration tests of a Java - JDBC application. If I try the following: Properties props = new Properties(); props.put("user", "sa"); props.put("password", ""); Class.forName("org.hsqldb.jdbcDriver"

  • Issue with inserting dynamically generated table into a div 2011-12-29

    I am dynamically generating rows of a table from the ajax response I am getting. The table headers are static/constant. I am finally writing this to a div on a page. The div has both horizontal and vertical scroll. My issue is this: If say I have 100

  • Jquery/JS No event handling on dynamically generated table 2012-02-22

    I have the following problem: I use an ajax query to retrieve customer info, the info returned populates a table. Only Last name, first name is displayed, plus a display:none field for customerID. I need that, when user doubleclicks a row in this tab

  • How to make Nhibernate generate table with Text field instead of nvarchar(255) 2009-05-26

    I'm trying to make NHibernate generate my schema/SQL 2008, and using the mapping below it keeps wanting to create an nvarchar(255) column instead of text...any ideas? <property name="AnnouncementText" column="AnnouncementText" type="StringClob"

  • Dynamically-generated table-name in PostgreSQL COPY command 2011-02-04

    This PostgreSQL COPY command works: copy tablename from E'c:\\abc\\a.txt'; but I want the tablename to be dynamically generated. How can I do this? --------------Solutions------------- You need to build a string, concatenating in the dynamic table na

  • Handling button clicks in dynamically generated table 2011-04-11

    <%foreach (var indication in Model.FindAll(m => m.Model != null && m.Model.Trx != null).OrderBy(m => m.Model.Trx.PrimarySponsor.Company)) { %> <tr> <td><%= indication.DisplayUser %></td> <td><%= in

  • How to delete a row from a dynamic generate table using jquery? 2011-05-09

    My code creates dynamically a table using jquery. I want to add delete functionality to the table. So when clicking on delete image the row should be delete. But deleting works fine just when the table is static. here id my code: createTable: functio

  • How to add class to dynamically generated table in jquery? 2015-01-11

    I have written a javascript code to dynamically generate a table ,How can I add class attribute to genrated table? I have tried using addClass(), and .className. But it did't work for me. Here is my code : var res = data.split("\n"); rows = res.lengt

  • Can't submit Typo3 forms when not logged in 2012-01-26

    I have made a simple plugin with a form but it won't post when I'm not logged in. Here is the file class.tx_gctest_pi1.php, created with Kickstarter. require_once(PATH_tslib.'class.tslib_pibase.php'); class tx_gctest_pi1 extends tslib_pibase { var $p

  • Center elemets of HorizontalScrollView when not enough to make it scroll 2012-03-23

    I have a Layout with a HorizontalScrollView containing a LinearLayout for a Menu where the contents are inflated with the contents of the DB. This works fine however when there are not enough elements to make the HSV scroll this does not fill the wid

  • C#, WinCE Listview : opening a form when list view item is clicked 2011-01-12

    I just want to ask what is the best way to open a new form when a list view item is clicked? Right now, I'm just using ShowDialog(). Thanks! :) --------------Solutions------------- In WinCE, using ShowDialog is the best way to open a new form, since

  • how to make dynamically generated forms with one to many relationships in django 2010-06-26

    i am trying to write a quiz system to learn django where users can add quizes to the system. my models look like from google.appengine.ext import db class Quiz(db.Model): title=db.StringProperty(required=True) created_by=db.UserProperty() date_create

  • cell span all columns of dynamicly generated table 2011-09-08

    For a display page in my app, I am generating several dynamic tables, whose column count changes depending on certain business logic. However, I'm required to have a "title" row that spans the whole table. Following the advice in the top-voted answer

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.736 (s). 13 q(s)