Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Cannot convert...

  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2002
    Messaggi
    20

    Cannot convert...



    Ciao ragazzi!
    Un Grazie anticipato per l'aiuto e scusate l'eventuale lessico improprio ma non sono un programmatore

    Ho un campo "Status" su Access di tipo bool.
    Vorrei che "ImageStatus" del gridview cambiasse in base al valore di "Status".
    Ma mi da questo errore:


    -Error 1 The best overloaded method match for '_Default.ControlloStatus(bool)' has some invalid arguments
    -Error 2 Argument '1': cannot convert from 'object' to 'bool'

    La Parte del codice interessata è la seguente...


    --- Default.aspx ---

    ....
    <asp:templatefield headertext="Status">
    <itemtemplate>
    <asp:Image runat="Server" ID="ImageStatus" ImageUrl='<%# ControlloStatus(Eval("Status")) %>' />
    </itemtemplate>
    </asp:templatefield>
    ....



    --- Default.aspx.cs ---

    ....
    public string ControlloStatus(bool b)
    {

    if (b == true)
    {

    return "http://..../Vero.gif";
    }
    else
    {
    return "http://..../Falso.gif";
    }

    }
    ....


    Marco

  2. #2
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    Eval("Status") restituisce un object mentre la tua funzione ControlloStatus accetta un booleano.

    Allora, o fai che la tua funzione accetti un object oppure le passi un booleano.
    Nel 2° caso, in c#, (che non uso) credo che sia qualcosa del genere:

    ImageUrl='<%# (bool) ControlloStatus(Eval("Status")) %>'

    Pietro

  3. #3
    Utente di HTML.it
    Registrato dal
    Mar 2002
    Messaggi
    20
    Grazie, mi potresti fare un piccolo esempio riferito al primo caso?

    il secondo caso esposto continua a ripetere lo stesso errore

  4. #4
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    per adesso ti mando la paginetta di prova che ho fatto:
    nel mio caso, naturalmente, il compo vero/falso si chiama si_no

    codice:
    <%@ Page Language="C#" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        
        protected string ControlloStatus(bool b)
        {
            if (b)
                return "http://..../Vero.gif";
            else
                return "http://..../Falso.gif";
    
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            libreria.ModuloWeb.DataBind(this.GridView1, MioModulo.StringaConnessioneTest, "select si_no from campi", null);
            
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Pagina senza titolo</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <img alt='<%# ControlloStatus((bool)Eval("si_no")) %>' src='<%# ControlloStatus((bool)Eval("si_no")) %>' />
                        </ItemTemplate>
                    </asp:TemplateField>
                    
                </Columns>
            </asp:GridView>
        
        </div>
        </form>
    </body>
    </html>
    Pietro

  5. #5
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    L'altra versione è questa: a me funziona :master: però occhio perchè io uso il basic e non vorrei fare pasticci
    codice:
    <%@ Page Language="C#" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        
        protected string ControlloStatus(object b)
        {
            if(b != DBNull.Value)
                if ((bool) b)
                    return "http://..../Vero.gif";
                else
                    return "http://..../Falso.gif";
            else
                return "http://..../Falso.gif";
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            libreria.ModuloWeb.DataBind(this.GridView1, MioModulo.StringaConnessioneTest, "select si_no from campi", null);
            
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Pagina senza titolo</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <img alt='<%# ControlloStatus(Eval("si_no")) %>' src='<%# ControlloStatus(Eval("si_no")) %>' />
                        </ItemTemplate>
                    </asp:TemplateField>
                    
                </Columns>
            </asp:GridView>
        
        </div>
        </form>
    </body>
    </html>
    Pietro

  6. #6
    Utente di HTML.it
    Registrato dal
    Mar 2002
    Messaggi
    20
    Una sola parola... 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 © 2025 vBulletin Solutions, Inc. All rights reserved.