Si...hai ragione!!!
Ecco la mia soluzione non proprio bella!!!
<script runat="server">
Dim NRecord As Integer
Dim TotRecord As Integer
Dim NColonne As Integer
Dim UltimaColonna As Integer
Dim Verifica As String
Dim VerificaColonne As String
Protected Sub PageCategories_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
NColonne = 5
NRecord = 1
Verifica = "NO"
Dim TempTotRecord As System.Data.DataView = DirectCast(SqlDataSourceElencoCategorie.[Select](DataSourceSelectArguments.Empty), DataView)
TotRecord = TempTotRecord.Count.ToString()
ltvElencoCategorie.DataBind()
End Sub
Protected Sub ltvElencoCategorie_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ltvElencoCategorie.ItemDataBound
If (e.Item.ItemType = ListViewItemType.DataItem) Then
Dim ConnMacchinari As SqlConnection
Dim CommMacchinari As SqlCommand
Dim ReadMacchinari As SqlDataReader
ConnMacchinari = New SqlConnection()
ConnMacchinari.ConnectionString = ConfigurationManager.ConnectionStrings("CBSCompanyReadConnectionString").ConnectionString
CommMacchinari = New SqlCommand()
CommMacchinari.CommandType = CommandType.Text
CommMacchinari.CommandText = "SELECT ID_Macchinario, ID_Categorie FROM [Macchinari_ENG] WHERE (ID_Categorie LIKE @ID_Categorie)"
CommMacchinari.Parameters.Add(New SqlParameter("@ID_Categorie", ";" & DirectCast(e.Item.DataItem, DataRowView).Row("ID_Categoria").ToString() & ";"))
CommMacchinari.Connection = ConnMacchinari
CommMacchinari.Connection.Open()
ReadMacchinari = CommMacchinari.ExecuteReader()
Dim plc As PlaceHolder = DirectCast(e.Item.FindControl("itemPlaceHolder"), PlaceHolder)
Dim Tabella As New Literal
Dim TabellaTemp As New Literal
Dim StrutturaTabella As String
If ReadMacchinari.HasRows = True Then
Dim TotMacchinariXCat As Integer
While ReadMacchinari.Read()
TotMacchinariXCat = TotMacchinariXCat + 1
End While
StrutturaTabella = "<table width=""152px"" height=""152px"" border=""0px"" align=""center"" cellpadding=""0"" cellspacing=""0"" class=""box""><tr><td valign=""middle"" align=""center"" style=""background:url(../../images/sistema/cerchio_arancio.png) no-repeat;""><span class=""testograndecerchio""><b>" & TotMacchinariXCat & "</b></span><br><a href=""2" & DirectCast(e.Item.DataItem, DataRowView).Row("ID_Categoria").ToString() & "-" & RegExp.UrlFormat(DirectCast(e.Item.DataItem, DataRowView).Row("Titolo").ToString()) & "-" & TotMacchinariXCat & ".aspx"" style=""font-weight:normal; text-decoration: none;""><span class=""testonormalecerchio"">" & DirectCast(e.Item.DataItem, DataRowView).Row("Titolo").ToString() & "</span></a></td></tr></table>"
Else
'Exit Sub
StrutturaTabella = "<table width=""152px"" height=""152px"" border=""0px"" align=""center"" cellpadding=""0"" cellspacing=""0"" class=""box""><tr><td valign=""middle"" align=""center"" style=""background:url(../../images/sistema/cerchio_arancio.png) no-repeat;""><span class=""testograndecerchio""><b>0</b></span><br><span class=""testonormalecerchio"">" & DirectCast(e.Item.DataItem, DataRowView).Row("Titolo").ToString() & "</span></td></tr></table>"
End If
ReadMacchinari.Close()
CommMacchinari.Connection.Close()
CommMacchinari.Dispose()
ConnMacchinari.Dispose()
If NRecord = NColonne Then
If Verifica = "OK" Then
UltimaColonna = 5
NColonne = NColonne + 4
Verifica = "NO"
TabellaTemp.Text = "</tr></table></td>"
plc.Controls.Add(TabellaTemp)
Else
UltimaColonna = 4
NColonne = NColonne + 5
Verifica = "OK"
TabellaTemp.Text = "</tr></table></td>"
plc.Controls.Add(TabellaTemp)
End If
If UltimaColonna = 5 Then
If (TotRecord - NColonne + 1) < 0 Then
If ((TotRecord - NColonne + 1) + 5) Mod 2 = 0 Then
Tabella.Text = "</tr><tr><td><table width=""1%"" height=""1%"" border=""0px"" align=""center"" cellpadding=""0"" cellspacing=""0"" style=""padding-right:162px;""><tr><td>" & StrutturaTabella & "</td>"
Else
Tabella.Text = "</tr><tr><td><table width=""1%"" height=""1%"" border=""0px"" align=""center"" cellpadding=""0"" cellspacing=""0""><tr><td>" & StrutturaTabella & "</td>"
End If
Else
Tabella.Text = "</tr><tr><td><table width=""1%"" height=""1%"" border=""0px"" align=""center"" cellpadding=""0"" cellspacing=""0""><tr><td>" & StrutturaTabella & "</td>"
End If
ElseIf UltimaColonna = 4 Then
If (TotRecord - NColonne + 1) < 0 Then
If ((TotRecord - NColonne + 1) + 5) Mod 2 = 0 Then
Tabella.Text = "</tr><tr><td><table width=""1%"" height=""1%"" border=""0px"" align=""center"" cellpadding=""0"" cellspacing=""0"" style=""padding-right:162px;""><tr><td>" & StrutturaTabella & "</td>"
Else
Tabella.Text = "</tr><tr><td><table width=""1%"" height=""1%"" border=""0px"" align=""center"" cellpadding=""0"" cellspacing=""0""><tr><td>" & StrutturaTabella & "</td>"
End If
Else
Tabella.Text = "</tr><tr><td><table width=""1%"" height=""1%"" border=""0px"" align=""center"" cellpadding=""0"" cellspacing=""0""><tr><td>" & StrutturaTabella & "</td>"
End If
End If
Else
If Verifica <> "OK" Then
If VerificaColonne = "" Then
TabellaTemp.Text = "<td><table width=""1%"" height=""1%"" border=""0px"" align=""center"" cellpadding=""0"" cellspacing=""0""><tr>"
plc.Controls.Add(TabellaTemp)
VerificaColonne = "NO"
End If
UltimaColonna = 4
Else
UltimaColonna = 5
End If
Tabella.Text = "<td>" & StrutturaTabella & "</td>"
End If
plc.Controls.Add(Tabella)
NRecord = NRecord + 1
End If
End Sub
</script>
<table width="100%" height="100%" border="0px" align="center" cellpadding="13" cellspacing="0">
<tr>
<td valign="middle" align="center"><span class="titolopiccologrigio"> </span></td>
</tr>
<tr>
<td valign="top" align="center">
<table width="77%" border="0px" align="center" cellpadding="0" cellspacing="0">
<tr>
<asp:ListView runat="server" ID="ltvElencoCategorie" DataSourceID="SqlDataSourceElencoCategorie">
<ItemTemplate>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder" />
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSourceElencoCategorie" runat="server" ConnectionString="<%$ ConnectionStrings:CompanyReadConnectionString %>" SelectCommand="SELECT * FROM [Categorie] WHERE ID_Appartenenze = 1 ORDER BY ID_Categoria"></asp:SqlDataSource>
</tr>
</table>
</td>
</tr>
</table>
La struttura di questo script è oltretutto una struttura fatta in questo modo
item|item|item|item
item|item|item|item|item
item|item|item|item
item|item|item|item|item
Quindi scrive una riga di 4 record e la succecciva di 5 record e cosi via!
Concordo con il tuo pensiero!!!Quelli della microsoft hanno proprio fatto un megalavoro!!!Che teste ragazzi!!!
Cmq visto che l'hai scritto anche tu un po di codice pubblicalo!
Grazie
Tommaso