locked
condition in listview RRS feed

  • Question

  • User1136423486 posted

    <td>
    <asp:Label runat="server" style="display:none"><%# Convert.ToInt32(Eval("ElapsedMilliseconds")) < Convert.ToInt32(Eval("Green"))%></asp:Label>
    <img src="img/green.png" alt="green_status" width="10" height="10" /></td>
    <td> <asp:Label runat="server" style="display:none"><%# Convert.ToInt32(Eval("ElapsedMilliseconds")) >= Convert.ToInt32(Eval("Green")) && Convert.ToInt32(Eval("ElapsedMilliseconds")) < Convert.ToInt32(Eval("Orange"))%></asp:Label>
    <img src="img/orange.png" alt="orange_status" width="10" height="10" />

    </td>

    if i give both the condition value is display in list view please give some suggestion 

    Tuesday, June 16, 2020 6:05 AM

Answers

  • User1136423486 posted

    <td>
    <span runat="server" visible='<%#(int)Eval("ElapsedMilliseconds")< (int) Eval("Green") %>'>

    <asp:Image runat="server" ImageUrl="img/green.png" width="10" Height="10"/>
    </span>

    <span runat="server" visible='<%#(int)Eval("ElapsedMilliseconds")>= (int) Eval("Green") && (int)Eval("ElapsedMilliseconds")< (int) Eval("Orange") %>'>

    <asp:Image runat="server" ImageUrl="img/Orange.png" width="10" Height="10"/>
    </span>
    <span runat="server" visible='<%#(int)Eval("ElapsedMilliseconds")>= (int) Eval("Red") %>'>

    <asp:Image runat="server" ImageUrl="img/Red.png" width="10" Height="10"/>
    </span>
    </td>

    I found answer.Thank you support

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 16, 2020 8:37 AM

All replies

  • User-719153870 posted

    Hi Noobewolf,

    if i give both the condition value is display in list view please give some suggestion 

    Are you trying to show/hide imgs depending on the value of the label before them?

    If so, you can use the juqery each() method to loop all the <td> elements and compare the <span>(Label in html) value with "true" or "false".

    Please refer to below code:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-3.4.1.min.js"></script>
        <script>
            $(function () {
                $("td").each(function () {
                    var lab = $(this).find("span").text();
                    var img = $(this).find("img");
                    if (lab=="False") {
                        img.hide();
                    }
                })
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:ListView ID="ListView1" runat="server">
                    <ItemTemplate>
                        <table>
                            <tr>
                                <td>
                                    <asp:Label runat="server" style="display:none"><%# Convert.ToInt32(Eval("ElapsedMilliseconds")) < Convert.ToInt32(Eval("Green"))%></asp:Label>
                                    <img src="img/green.png" alt="green_status" width="10" height="10" /></td>
                                <td>
                                    <asp:Label runat="server" style="display:none"><%# Convert.ToInt32(Eval("ElapsedMilliseconds")) >= Convert.ToInt32(Eval("Green")) && Convert.ToInt32(Eval("ElapsedMilliseconds")) < Convert.ToInt32(Eval("Orange"))%></asp:Label>
                                    <img src="img/orange.png" alt="orange_status" width="10" height="10" /></td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:ListView>
            </div>
        </form>
    </body>
    </html>

    Or if i misunderstood, please clarify.

    Thanks,

    Yang Shen

    Tuesday, June 16, 2020 6:33 AM
  • User1136423486 posted

    your below is code is not working 

    what i need means?

    i have value of ellpasedmilliseconds and green with that i have check the condition

    true means one image will display false means another image will display.but i have three condition 

    with that i will display image 

    Tuesday, June 16, 2020 6:55 AM
  • User-719153870 posted

    Dear Noobewolf,

    Noobewolf

    i have value of ellpasedmilliseconds and green with that i have check the condition

    true means one image will display false means another image will display.

    My understanding is, if the ellpasedmillisecondsgreen then show the green.png and hide the orange.png, else if ellpasedmilliseconds >= green && < orange then hide the green.png and show orange.png.

    Sorry if my description is unclear, obviously above code is not complete, please check below complete demo:

    aspx:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-3.4.1.min.js"></script>
        <script>
            $(function () {
                $("td").each(function () {
                    var lab = $(this).find("span").text();
                    var img = $(this).find("img");
                    if (lab=="False") {
                        img.hide();
                    }
                })
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:ListView ID="ListView1" runat="server">
                    <ItemTemplate>
                        <table border="1">
                            <tr>
                                <td style="width:50px;height:22px">
                                    <asp:Label runat="server" style="display:none"><%# Convert.ToInt32(Eval("ElapsedMilliseconds")) < Convert.ToInt32(Eval("Green"))%></asp:Label>
                                    <img src="files/green.png" alt="green_status" width="10" height="10" /></td>
                                <td style="width:50px;height:22px">
                                    <asp:Label runat="server" style="display:none"><%# Convert.ToInt32(Eval("ElapsedMilliseconds")) >= Convert.ToInt32(Eval("Green")) && Convert.ToInt32(Eval("ElapsedMilliseconds")) < Convert.ToInt32(Eval("Orange"))%></asp:Label>
                                    <img src="files/orange.png" alt="orange_status" width="10" height="10" /></td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:ListView>
            </div>
        </form>
    </body>
    </html>

    cs:

            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.AddRange(new DataColumn[3] { new DataColumn("ElapsedMilliseconds"), new DataColumn("Green"), new DataColumn("Orange") });
                    dt.Rows.Add("1", "5", "10");
                    dt.Rows.Add("2", "5", "10");
                    dt.Rows.Add("3", "5", "10");
                    dt.Rows.Add("4", "5", "10");
                    dt.Rows.Add("5", "5", "10");
                    dt.Rows.Add("6", "5", "10");
                    dt.Rows.Add("7", "5", "10");
                    ListView1.DataSource = dt;
                    ListView1.DataBind();
                }
            }

    result:

    If this is not what you want still, please share more code from your side and clarify which part of my code need to be modified to meet the true requirement.

    Thanks,

    Yang Shen

    Tuesday, June 16, 2020 7:52 AM
  • User1136423486 posted

    <td>
    <span runat="server" visible='<%#(int)Eval("ElapsedMilliseconds")< (int) Eval("Green") %>'>

    <asp:Image runat="server" ImageUrl="img/green.png" width="10" Height="10"/>
    </span>

    <span runat="server" visible='<%#(int)Eval("ElapsedMilliseconds")>= (int) Eval("Green") && (int)Eval("ElapsedMilliseconds")< (int) Eval("Orange") %>'>

    <asp:Image runat="server" ImageUrl="img/Orange.png" width="10" Height="10"/>
    </span>
    <span runat="server" visible='<%#(int)Eval("ElapsedMilliseconds")>= (int) Eval("Red") %>'>

    <asp:Image runat="server" ImageUrl="img/Red.png" width="10" Height="10"/>
    </span>
    </td>

    I found answer.Thank you support

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 16, 2020 8:37 AM