asp.net - Unable to select item name in DropDownList on selectedindex_changed event? -



asp.net - Unable to select item name in DropDownList on selectedindex_changed event? -

code in page_load() event follows :-

sqlconnection c = new sqlconnection(conn); c.open(); sqlcommand cmd = new sqlcommand(); cmd.connection = c; cmd.commandtext = "select name employee1"; sqldatareader dr = cmd.executereader(); if (!ispostback) { while (dr.read()) { dropdownlist1.items.add(dr["name"].tostring()); } }

code in dropdownlist1_selectedindexchanged() event follows:-

label1.text = dropdownlist1.selecteditem.tostring();

i tried writing

label1.text = dropdownlist1.selecteditem.text; label1.text = dropdownlist1.selecteditem;

i wan't utilize name in next query

cmd.commandtext = "select salary employee1 name='" +dropdownlist1.selecteditem.text+"' ";

use if !page.ispostback bind data.

if (!page.ispostback) { //bind dropdown here sqlconnection c = new sqlconnection(conn); c.open(); sqlcommand cmd = new sqlcommand(); cmd.connection = c; cmd.commandtext = "select name employee1"; sqldatareader dr = cmd.executereader(); if (!ispostback) { while (dr.read()) { dropdownlist1.items.add(dr["name"].tostring()); } } }

asp.net

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -