i want to select any one value from dropdownlist1 according to that value, bound values in another dropdownlist2.
for ex,in dropdownlist1 there is class name like fy,sy,ty then according this if i choose fy class then in dropdownlist2 display the subjects in fy class but without click on any button.
pls help me fast. It is very urgent for me.
Thank you...!
Joginder BangerPosted Nov 29, 2014, 6:31 PM
as per your problem you need Two Table like these type.
class Table
classid classname
subject table
subjectid fk_classid Subject_name
Store Procedure
create proc Proc_bindclass
@classID int
as
begin
select subjectid,Subject_name from SubjectTable where fk_classid=@classid
end
In dropdownlist have one event selected_indexchanged. you can do this with the help of selected_indexchagned.
note: Don't forget Dropdownlist Autopostback=true. It's is by default false. if you forget this your selected_indexchanged can't work.
Design
Event
DataTable dt=new DataTable
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) {
SqlConnection con= new SqlConnection("Yourconnection string");
Sqlcommand Com= new Sqlcommand("Proc_bindclass",con);
com.commandType=commandType.StoreProcedure;
com.parameters.AddwithValue("@classID",dropdownlist.selectedvalue);
sqlDatareader rd=com.executeReader();
rd.load(dt);
//bind your DropDownlist2
} protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { //Load DropDownList3 }