Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

2 items in a dropdown

  • 21-07-2004 08:37AM
    #1
    Registered Users, Registered Users 2 Posts: 937 ✭✭✭


    hi, is it possible to have 2 items in a drop down box ie...variable1 - variable 2, but the value when selected is variable one, not both.....i know how to do it in asp but the same type of method doesnt work in asp.net

    any help much appreciated


Comments

  • Moderators, Politics Moderators, Paid Member Posts: 44,285 Mod ✭✭✭✭Seth Brundle


    [I haven't studied asp.net but] you can set the label in the dropdown to be the two items but the value for this to be variable1
    <option value="variable1" />variable1 - variable2
    is this what you mean?

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Registered Users, Registered Users 2 Posts: 937 ✭✭✭Diddy Kong


    ye, thats the way it works in classic asp, but dowsnt seem to work in the .net stuff


  • Moderators, Politics Moderators, Paid Member Posts: 44,285 Mod ✭✭✭✭Seth Brundle


    as I don't know .net I can't really comment but as far as I can see all you are trying to do is something like Response.Write(variable1 & " - " & variable2)
    What exactly is happening?

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Registered Users, Registered Users 2 Posts: 937 ✭✭✭Diddy Kong


    dropd1.DataValueField = "variable1"
    dropd1.DataTextField = "variable1" & " - " & "variable2"
    dropd1.databind
    thats what i have so far, both variables are bein pulled from sql, and below is the error i get
    System.Web.HttpException: DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a property with the name UPN - title.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Off the top of my head I reckon you're trying to Bind to a field called 'UPN - Title', is this correct? If so then the object you're binding to doesn't have a field with that name. Check the query you're using to retrieve the data and see what name that field has.

    It would be handy if you could post the actual code that you're using, both VB and any SQL you may be using.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 937 ✭✭✭Diddy Kong


    Dim sql1 as string = "select var1,var2 from UPN_Description where Factory=@fchoice&quot;
    Dim cmd1 as new SQLCommand(sql1, myConn)
    Cmd1.parameters.add(New SQLParameter("@fchoice&quot;,list.selecteditem.value))
    myConn.open()

    dropd1.datasource=cmd1.ExecuteReader(system.data.CommandBehavior.CloseConnection)
    dropd1.DataValueField = "var1"
    dropd1.DataTextField = "var2" & " - " & "var2"
    dropd1.databind
    dropd1.visible="true"

    if thats any help


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    dropd1.DataTextField = "var2" & " - " & "var2"
    

    Should be
    dropd1.DataTextField = "var2" 
    

    As what you're doing is concatenating strings to create a fieldname to bind the text too, which is throwing the DataBind.Eval error, and not concatenating the text that you want to display (which I suspect is what you were trying to do). That's why you're getting the error. Does this make sense?

    I'm sure you could combine the text into one with some clever SQL-ery.


  • Registered Users, Registered Users 2 Posts: 937 ✭✭✭Diddy Kong


    ok, if i add another sql query to the code, to concat the 2 variables, will the value of each concat option be one variable?

    ie option="var1 - var2"
    value="var1"


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Something like that, yeah, play around a bit and you'll work something out. 'Tis the fun of it.


  • Registered Users, Registered Users 2 Posts: 937 ✭✭✭Diddy Kong


    cheers, eventually got it working...


  • Advertisement
Advertisement