Featured post
c# - populate dropdown list from a list of objects -
in attempt of building 3-tier architecture c# asp.net application, i've started building class database used connecting database, class city has method each column in table cities, , cities class in have getcities method creates list of city objects , use datasource wizard set control use data getcities(). blanks in dropdown list. idea why?
        public list<city> getcities()     {         list<city> cities = new list<city>();         database db = new database();         sqlconnection conn = db.getconnection();         string sql = "select * cities";         sqlcommand cmd = new sqlcommand(sql, conn);         sqldatareader reader = cmd.executereader();          while (reader.read())         {             city c = new city(reader.getint32(0), reader.getstring(1).tostring());             cities.add(c);         }          db.closeconnection();         return cities;     } thanks
did set datatextfield, datavaluefield properties, , call databind?
at point try concept working possible, , start adding things in until locate problem. start brand new page, add dropdownlist don't touch data source or change properties, go directly codebehind , add in page_load:
dropdownlist1.datavaluefield = "id"; dropdownlist1.datatextfield = "name"; dropdownlist1.datasource = new[] {     new { id = 1, name = "alice" },     new { id = 2, name = "mike" },     new { id = 3, name = "john" } }; dropdownlist1.databind(); does work? me. try change datavaluefield, datatextfield, , datasource work customer list. broken now? know problem in customer list somewhere, not way you're binding data.
- Get link
- X
- Other Apps
Comments
Post a Comment