Problem with dropdownlist

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • looserash
    New Member
    • Mar 2008
    • 8

    Problem with dropdownlist

    HI,
    I have a problem with dropdownlist.i have populated dropdownlist.my problem is i have to place a particular item in ddl which is already stored in sql 2000 database.
  • indianmaestro
    New Member
    • Mar 2008
    • 16

    #2
    your question is not clear

    this may help if not.... ask the question clearly


    Sqlcommand cmd=new sqlcommand("sel ect items from table1",con);
    Sqldatareader dr=cmd.executer eader();

    while(dr.read() )
    {
    ddl.items.add(n ew listitems(dr[0].tostrint());
    }
    dr.close();

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      I guess, u want to show items selected which store in database.

      then
      SelectedVal is ur database value

      Dim iIndex As Int16 = 0
      Dim temp As ListItem
      For Each temp In ddl.Items
      If Trim(temp.Value ) = Trim(SelectedVa l) Then
      ddl.SelectedInd ex = iIndex
      Exit For
      End If
      iIndex = iIndex + 1
      Next

      Comment

      • nev
        Contributor
        • Oct 2007
        • 251

        #4
        Originally posted by looserash
        HI,
        I have a problem with dropdownlist.i have populated dropdownlist.my problem is i have to place a particular item in ddl which is already stored in sql 2000 database.
        just iterate through each record and add each item to your ddl. you can use for loop.

        Comment

        • looserash
          New Member
          • Mar 2008
          • 8

          #5
          okie.. thanks.

          i ll tell u wats happening here. i have 2 dropdownlist . one is section and another is subsection. so when i select an item in section correspondingly subsection dropdownlist will fill.. i have written the code in selected index changed.i ll save it.i am able to access that item from database place the item in section ddl but not in subsection ddl. i think this is clear .

          Comment

          • indianmaestro
            New Member
            • Mar 2008
            • 16

            #6
            section_selecte dindexchanged( )
            {

            //here write the code to get the sub sections from the table
            like suppose u have a table table1 and inthat colums1 contains the section and coloumn2 contains the subsection //
            string query=" select coloumn2 from table1 where section1='" + section.selecte ditem.tostring( ) +"'";


            sqlcommand cmd=new sql command(query,c onn);
            sqldatareader dr=cmd.executer eader();

            while(dr.read() )
            {
            subsections.ite ms.add(new listitems(dr[0].tostring()));
            }


            }


            hope this is clear

            Santhu.

            Comment

            • looserash
              New Member
              • Mar 2008
              • 8

              #7
              thanks a lot its working
              regards,

              Comment

              Working...