simple ddl attribute question

Discussion in 'C#' started by progfrog, Sep 25, 2008.

  1. #1
    Hi
    this is the content of my ddl list:
    John
    jake
    jay

    Their id's are : john=1 , jack=2, jay=3
    i want to reach two values to make this kind of statement: if (ddlnames.selectedvalue==2 || ddlnames.nextvalue==3)
    i want to get back jake and jay
    because i choose jack- the selected value in the ddl i do no know how to describe the value after it-

    how can I define the "nextvalue" in a code?

    is it ddl.selectedvalue+1??

    need u quickly
    progfrog
     
    progfrog, Sep 25, 2008 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    it should be selectedindex
     
    javaongsan, Sep 25, 2008 IP
  3. jgarrison

    jgarrison Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    VB.Net:

    Dim selectedNames As String
    selectedNames = ""

    If ddlnames.SelectedIndex = 1 Then
    selectedNames += " John"
    End If

    If ddlnames.SelectedIndex = 2 Then
    selectedNames += ", Jack"
    End If

    If ddlnames.SelectedIndex = 3 Then
    selectedNames += ", Jay"
    End If

    If selectedNames = "" Then
    selectedNames = "No names were selected"
    Else
    selectedNames = "Selected names: " + selectedNames
    End If

    Response.Write(selectedNames)

    C#:
    string selectedNames = null;
    selectedNames = "";

    if (ddlnames.SelectedIndex == 1) {
    selectedNames += " John";
    }

    if (ddlnames.SelectedIndex == 2) {
    selectedNames += ", Jack";
    }

    if (ddlnames.SelectedIndex == 3) {
    selectedNames += ", Jay";
    }

    if (string.IsNullOrEmpty(selectedNames)) {
    selectedNames = "No names were selected";
    } else {
    selectedNames = "Selected names: " + selectedNames;
    }

    Response.Write(selectedNames);


    I think that's what you're looking for. I'm better with VB.Net than with C# but I believe my syntax is correct.
    -Jim
     
    jgarrison, Oct 5, 2008 IP