问题描述
Am使用两页第一页将数据添加到表中,第二页显示数据.
这是表格(批次ID,Student1,student2,student3)
批次ID的第二个页面列表中的第二个应显示在Dropdownlist1中.
并且相应的学生必须显示在下拉列表2中.
示例示例:
(Batch101,Alex,Peter,Ben)
(批102,Stew,John,Mark)
Batch101,Batch102将显示在Dropdownlist1中.从Dropdownlist1中选择Batch101时,Dropdownlist2应显示Alex,Peter,Ben.
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.
推荐答案
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());
}
}
这篇关于如何从数据库添加下拉列表中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!