Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

2 items in a dropdown

  • 21-07-2004 8: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 Posts: 41,217 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?


  • 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 Posts: 41,217 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?


  • 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