简体   繁体   中英

how can i bind image in listbox

I have a listbox on my page where i am checking the driver status if driver status is 1 then i change the font color in red Status 2 then i change color of font in listbox in green . Like that i want that i place a image with item in listbox if status will be 1 then i display a red image with that . How can i do that for you i am placing my aspx and c# code below

<asp:ListBox ID="ddlDriver" Width="100%" AutoPostBack="true" OnSelectedIndexChanged="ddlDriver_SelectedIndexChanged"
                                        runat="server" BackColor="White" Height="380px"></asp:ListBox>

C# Code for listbox item font color

 protected void ColorFillDrvier()
{
    for (int i = 0; i < ddlDriver.Items.Count; i++)
    {
        int drvierNo = Convert.ToInt32(ddlDriver.Items[i].Value);
        Drivers _driv = DataRepository.DriversProvider.GetByDriverNumber(drvierNo);

        if (_driv.DriverStatus == 1)
        {

            ddlDriver.Items[i].Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "red");

        }
        else if (_driv.DriverStatus == 2)
        {

            ddlDriver.Items[i].Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "green");

        }
        else if (_driv.DriverStatus == 3)
        {

            ddlDriver.Items[i].Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "yellow");
        }
        else if (_driv.DriverStatus == 4)
        {

            ddlDriver.Items[i].Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "blue");
        }
        else if (_driv.DriverStatus == 5)
        {

            ddlDriver.Items[i].Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "black");
        }

    }

}

How can i do that . Thanks in advance for you all

Try this link and let me know if it is useful :

http://www.codeproject.com/Articles/2091/ListBox-with-Icons

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM