Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Array di controlli

  1. #1

    Array di controlli

    Ciao,

    come posso fare per visualizzare con un ciclo i valori

    restituiti da un tabella e inserirli in varie label?

    questo è il mio codice:

    lb_Titolo1.Text = dsDVD.DVD.Rows(1).Item("Titolo").ToString()
    lb_Titolo2.Text = dsDVD.DVD.Rows(2).Item("Titolo").ToString()
    lb_Titolo3.Text = dsDVD.DVD.Rows(3).Item("Titolo").ToString()
    lb_Titolo4.Text = dsDVD.DVD.Rows(4).Item("Titolo").ToString()
    lb_Titolo5.Text = dsDVD.DVD.Rows(5).Item("Titolo").ToString()
    lb_Titolo6.Text = dsDVD.DVD.Rows(6).Item("Titolo").ToString()
    lb_Titolo7.Text = dsDVD.DVD.Rows(7).Item("Titolo").ToString()
    lb_Titolo8.Text = dsDVD.DVD.Rows(8).Item("Titolo").ToString()
    lb_Titolo9.Text = dsDVD.DVD.Rows(9).Item("Titolo").ToString()

    grazie!

  2. #2
    usando un array di controlli,
    per esempio tu ora stai usando delle label
    quindi
    codice:
    System.Web.UI.WebControls.Label[] arrayDiLabels=
    {lb_Titolo1,lb_Titolo2,lb_Titolo3,lb_Titolo4,lb_Titolo5,lb_Titolo6,lb_Titolo7,lb_Titolo8,lb_Titolo9};
    for(int i=0,max=arrayDiLabels.Length;i<max;i++){
       arrayDiLabels[i].Text=dsDVD.DVD.Rows(i+1).Item("Titolo").ToString();
    }

  3. #3
    il codice è in c#?

    ho dimenticato a dire che uso VBNET

    grazie

  4. #4
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    Originariamente inviato da illusione
    il codice è in c#?

    ho dimenticato a dire che uso VBNET

    grazie
    e con ciò? Traduci

    ps. anche io uso vb.net

    codice:
    <%@ Page Language="C#" %>
    <%@ Import Namespace="l=libreria.ModuloWeb" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = l.GetDataTable(gl.StringaConnessioneTest, "select * from regioni");
            for (int i = 0; i < 20; i++)
            {
                Label lb = (Label)this.FindControl("Label" + (i+1).ToString());
                lb.Text = dt.Rows[i][1].ToString();
            }        
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Pagina senza titolo</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label7" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label8" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label9" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label10" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label11" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label12" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label13" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label14" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label15" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label16" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label17" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label18" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label19" runat="server" Text="Label"></asp:Label>
    
            <asp:Label ID="Label20" runat="server" Text="Label"></asp:Label>
    
        </form>
    </body>
    </html>
    Pietro

  5. #5
    OK!

    Ho trovato il traduttore qui:

    http://authors.aspalliance.com/aldot...translate.aspx

    Mi hai risolto un problema enorme

    grazie mille!


  6. #6
    ciao

    ho spostato la dichiarazione fuori dalla routine Page pre render

    Dim lb_Titolo As System.Web.UI.WebControls.Label() = {lb_Titolo0, lb_Titolo1, lb_Titolo2, lb_Titolo3, lb_Titolo4, lb_Titolo5, lb_Titolo6, lb_Titolo7, lb_Titolo8, lb_Titolo9}

    per renderlo visibile a tutti ma mi viene segnalato

    Riferimento a un oggetto non impostato su un'istanza di oggetto.

    come si deve dichiarare?

    grazie!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.