解决这个问题 [英] solve the problem

查看:72
本文介绍了解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个表,课程,教师,学生.我已经使用主键约束&来实现表之间的一对多关系.外键约束.我的设计包含一个下拉列表&两个datagridviews.我将课程表的公共列绑定到dropdownlist.当我选择组合框项目时,它将在一个gridview&中显示相应的教员表记录.在另一个gridview中的学生表记录.这些仅在窗体加载中.我在C#Windows窗体中获得结果.但是在ASP.net中却没有得到相同的结果.它具有约束力
排到下拉列表的课程编号&教师表到gridview1,学生表到gridview2.

问题是当我选择dropdownlist项目时,相应的表格数据未显示在相应的gridviews中.但是我在C#Winforms中获得了具有相同加载代码(dropdownlist == combobox)的表单加载代码中的结果. .

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";
}

推荐答案

DropDownList的AutoPostBack属性是否设置为True?
如果不是,则在您使用的DropDownList属性中将其设置为True.

如果上面的代码没有问题,它必须可以工作.
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.


这篇关于解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆