How to add color to dropdownlist based on value from SQL Query Statement.

Discussion in 'ASP .Net Web Controls' started by Rob, Jan 26, 2004.

  1. Rob

    Rob Guest

    I want to be able to color code my dropdown list based on the status
    of the users within the list. I have a SQL Query (stored Procedure)
    that return the following data. (UserID, UserName, Status).

    I bind the data like this from returning the data from a
    SqlDataReader:

    ' dropdownlisting of all users
    With UserList
    .DataSource = GetUsersDropDown()
    .DataTextField = "vcUserName"
    .DataValueField = "vcUserID"
    .DataBind()
    .Items.Insert(0, "-- Select a User --")
    .SelectedIndex = 0
    End With

    The GetUsersDropDown Function:

    Public Function GetUsersDropDown() As SqlDataReader
    Dim dr As SqlDataReader
    Dim strConn = New
    SqlConnection(HttpContext.Current.Application("strConn"))
    Dim cmdSelect = New SqlCommand("spSOCSRListX", strConn)
    cmdSelect.CommandType = CommandType.StoredProcedure
    strConn.Open()
    dr = cmdSelect.ExecuteReader()
    Return dr
    strConn.Close()
    End Function



    The Function returns data like (10, Joe Burns, 1). I want to be able
    to identify the status (3rd column) or the user and based on the
    results (1-active, 0-inactive). Color the dropdown item a either red
    or white.

    Please help Im getting desperate....

    Many Thanks
     
    Rob, Jan 26, 2004
    #1
    1. Advertising

  2. You cannot color the dropdown item conditionally. There is a hack to allow
    you to do this. If you care, you can replace the dropdown with a select tag.
    That will allow you to customize the options somewhat.

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "Rob" <> wrote in message
    news:...
    > I want to be able to color code my dropdown list based on the status
    > of the users within the list. I have a SQL Query (stored Procedure)
    > that return the following data. (UserID, UserName, Status).
    >
    > I bind the data like this from returning the data from a
    > SqlDataReader:
    >
    > ' dropdownlisting of all users
    > With UserList
    > .DataSource = GetUsersDropDown()
    > .DataTextField = "vcUserName"
    > .DataValueField = "vcUserID"
    > .DataBind()
    > .Items.Insert(0, "-- Select a User --")
    > .SelectedIndex = 0
    > End With
    >
    > The GetUsersDropDown Function:
    >
    > Public Function GetUsersDropDown() As SqlDataReader
    > Dim dr As SqlDataReader
    > Dim strConn = New
    > SqlConnection(HttpContext.Current.Application("strConn"))
    > Dim cmdSelect = New SqlCommand("spSOCSRListX", strConn)
    > cmdSelect.CommandType = CommandType.StoredProcedure
    > strConn.Open()
    > dr = cmdSelect.ExecuteReader()
    > Return dr
    > strConn.Close()
    > End Function
    >
    >
    >
    > The Function returns data like (10, Joe Burns, 1). I want to be able
    > to identify the status (3rd column) or the user and based on the
    > results (1-active, 0-inactive). Color the dropdown item a either red
    > or white.
    >
    > Please help Im getting desperate....
    >
    > Many Thanks
     
    Alvin Bruney [MVP], Jan 26, 2004
    #2
    1. Advertising

  3. Rob

    Eran Amitai Guest

    Rob,

    I don't believe there's any way to color items in a dropdownlist. If this is
    really important to you you could implement an input box with a drop button
    that drops down an IFrame or a positioned HTML table, but that's a lot of
    work.

    Eran

    "Rob" <> wrote in message
    news:...
    > I want to be able to color code my dropdown list based on the status
    > of the users within the list. I have a SQL Query (stored Procedure)
    > that return the following data. (UserID, UserName, Status).
    >
    > I bind the data like this from returning the data from a
    > SqlDataReader:
    >
    > ' dropdownlisting of all users
    > With UserList
    > .DataSource = GetUsersDropDown()
    > .DataTextField = "vcUserName"
    > .DataValueField = "vcUserID"
    > .DataBind()
    > .Items.Insert(0, "-- Select a User --")
    > .SelectedIndex = 0
    > End With
    >
    > The GetUsersDropDown Function:
    >
    > Public Function GetUsersDropDown() As SqlDataReader
    > Dim dr As SqlDataReader
    > Dim strConn = New
    > SqlConnection(HttpContext.Current.Application("strConn"))
    > Dim cmdSelect = New SqlCommand("spSOCSRListX", strConn)
    > cmdSelect.CommandType = CommandType.StoredProcedure
    > strConn.Open()
    > dr = cmdSelect.ExecuteReader()
    > Return dr
    > strConn.Close()
    > End Function
    >
    >
    >
    > The Function returns data like (10, Joe Burns, 1). I want to be able
    > to identify the status (3rd column) or the user and based on the
    > results (1-active, 0-inactive). Color the dropdown item a either red
    > or white.
    >
    > Please help Im getting desperate....
    >
    > Many Thanks
     
    Eran Amitai, Jan 27, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anonymous
    Replies:
    0
    Views:
    1,548
    Anonymous
    Oct 13, 2005
  2. Boris Twila
    Replies:
    0
    Views:
    380
    Boris Twila
    Nov 14, 2006
  3. Balaji
    Replies:
    0
    Views:
    484
    Balaji
    Jul 7, 2003
  4. Guy Hocking

    ASP / SQL Query - Conditional SELECT Statement

    Guy Hocking, Jan 21, 2004, in forum: ASP General
    Replies:
    7
    Views:
    215
    Bob Barrows
    Jan 21, 2004
  5. Kamaljeet Saini
    Replies:
    0
    Views:
    503
    Kamaljeet Saini
    Feb 13, 2009
Loading...

Share This Page