Click here to Skip to main content
14,733,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three tables course,faculty,student.I have implemented one to many relation between tables using primary key constraint & foreign key constraint.my design consists of one dropdownlist & two datagridviews.I bind the common column of course table to dropdownlist.when i select the combobox item it will display corresponding faculty table records in one gridview & student table records in another gridview.these are in form load only.I get the result in C# Windows forms.but i am not getting same result in ASP.net. it is binding
courseid to dropdownlist & faculty table to gridview1,student table to gridview2.

problem is when I select the dropdownlist item the corresponding table data does not displayed in corresponding gridviews.but I get the result in C# winforms with same bellow code(dropdownlist==combobox) in form load code.if any body knows please give solution clearly.

private void Form1_Load(object sender, EventArgs e)
{
string cs = "uid=sa;pwd=nanda;database=satyadatabase";
SqlConnection conn = new SqlConnection(cs);
// conn.Open();
SqlCommand cmd1 = new SqlCommand("select * from course", conn);
SqlCommand cmd2 = new SqlCommand("select * from faculty", conn);
SqlCommand cmd3 = new SqlCommand("select * from student", conn);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
SqlDataAdapter da3 = new SqlDataAdapter(cmd3);
DataSet ds = new DataSet();
da1.Fill(ds, "coursenew");
da2.Fill(ds, "facultynew");
da3.Fill(ds, "studentnew");
ds.Relations.Add("coursefac", ds.Tables["coursenew"].Columns["courseid"], ds.Tables["facultynew"].Columns["courseid"]);
ds.Relations.Add("coursest", ds.Tables["coursenew"].Columns["courseid"], ds.Tables["studentnew"].Columns["courseid"]);
Dropdownlist1.DataSource = ds.Tables["coursenew"];
Dropdownlist1.DataValueField = "courseid";
gridfaculty.DataSource = ds.Tables["coursenew"];
gridfaculty.DataMember = "coursefac";
gridstudent.DataSource = ds.Tables["coursenew"];
gridstudent.DataMember = "coursest";
}
Posted
Updated 12-Aug-10 7:23am
v2

1 solution

Is the AutoPostBack Property of DropDownList is Set to True ??
If NOT then set it to True in the Property of DropDownList you are using.

It must work if there is no problem in the above code.
   
Comments
Sandeep Mewara 12-Aug-10 14:47pm
   
Comment from OP: yes i set the dropdownlist property autopostback is true.but it is not coming

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