Click here to Skip to main content
15,887,392 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Am using two pages first page to add data to tables and second table is to display the data .

this is Table (Batch id ,Student1,student2,student3)

in second Page List of Batch id should be displayed in Dropdownlist1.
and corresponding students has to be displayed in dropdownlist2.

Example Consider :

(Batch101,Alex,Peter,Ben)

(Batch102,Stew,John,Mark)

Batch101, Batch102 will be Displayed in Dropdownlist1 . When Batch101 is selected from Dropdownlist1, Dropdownlist2 should display Alex,Peter,Ben.
Posted
Updated 22-Mar-12 8:11am
v2

C#
String StrCon="Your Connection";
SqlConnection objcon=new sqlconnection(StrCon);
objcon.open();

string query="select Student from table where Batchid='"+Dropdownlist1.selectedItem.text+"'";

sqlcommand cmd=new sqlcommand(query,objcon);
sqldatareader dr;
dr=cmd.executereader();

if (dr.hasrows)
  {while(dr.read())
  {
    dropdownlist2.items.add(dr[0].tostring());
  }
}
 
Share this answer
 
v2
Comments
Dean Oliver 22-Mar-12 14:42pm    
Gave you 4 because although this is a good solution you promoting sql injection attacks.
mali_angel 5-Aug-13 23:23pm    
can anyone tell me the java code for above scenario?
Gopal Rakhal 22-Mar-12 21:05pm    
plz improve this....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900