早教吧作业答案频道 -->其他-->
设计一个选课程序,要求:该选课的运行界面包含2个列表框,左边为已开设的课程名称,通过formload事件加载,当单击某课程名称后,将该课程加入到右边的列表框中,并在左边的列表框中
题目详情
设计一个选课程序,要求:该选课的运行界面包含2个列表框,左边为已开设的课程名称,通过form load事件加载,当单击某课程名称后,将该课程加入到右边的列表框中,并在左边的列表框中删除该课程,当右边的课程数已满五门时,不允许再加入
▼优质解答
答案和解析
左边绑定课程名称,单击后把选中的加入右边列表,然后删除选择项,当加入右边列表时,首先判断是不是已满五门课程了
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ListBox1.Items.Clear();
DataTable dt = Common.SqlHelper.GetDataTabel("select * from tb_Course");
ListBox1.DataSource = dt;
ListBox1.DataTextField = "CourseName";
ListBox1.DataValueField = "ID";
ListBox1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (ListBox2.Items.Count >= 5)
{
Page.ClientScript.RegisterStartupScript(this.GetType(),"","alert('已经选够5门了')",true);
return;
}
if (ListBox2.Items.Count > 0)
{
int count = 0;
for (int i = 0; i < ListBox2.Items.Count; i++)
{
if (ListBox1.SelectedValue.ToString() == ListBox2.Items[i].Value.ToString())
{
count = 1;
break;
}
}
if (count == 1)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('已经选过这门了')", true);
}
else
{
ListBox2.Items.Add(new ListItem(ListBox1.SelectedItem.ToString(), ListBox1.SelectedValue.ToString()));
ListBox1.Items.Remove(ListBox1.Items.FindByValue(ListBox1.SelectedValue.ToString()));
}
}
else
{
ListBox2.Items.Add(new ListItem(ListBox1.SelectedItem.ToString(), ListBox1.SelectedValue.ToString()));
ListBox1.Items.Remove(ListBox1.Items.FindByValue(ListBox1.SelectedValue.ToString()));
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ListBox1.Items.Clear();
DataTable dt = Common.SqlHelper.GetDataTabel("select * from tb_Course");
ListBox1.DataSource = dt;
ListBox1.DataTextField = "CourseName";
ListBox1.DataValueField = "ID";
ListBox1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (ListBox2.Items.Count >= 5)
{
Page.ClientScript.RegisterStartupScript(this.GetType(),"","alert('已经选够5门了')",true);
return;
}
if (ListBox2.Items.Count > 0)
{
int count = 0;
for (int i = 0; i < ListBox2.Items.Count; i++)
{
if (ListBox1.SelectedValue.ToString() == ListBox2.Items[i].Value.ToString())
{
count = 1;
break;
}
}
if (count == 1)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('已经选过这门了')", true);
}
else
{
ListBox2.Items.Add(new ListItem(ListBox1.SelectedItem.ToString(), ListBox1.SelectedValue.ToString()));
ListBox1.Items.Remove(ListBox1.Items.FindByValue(ListBox1.SelectedValue.ToString()));
}
}
else
{
ListBox2.Items.Add(new ListItem(ListBox1.SelectedItem.ToString(), ListBox1.SelectedValue.ToString()));
ListBox1.Items.Remove(ListBox1.Items.FindByValue(ListBox1.SelectedValue.ToString()));
}
}
看了 设计一个选课程序,要求:该选...的网友还看了以下:
如何在Matlab中利用已产生的m序列产生gold序列?rt,阶数是6,两个m序列系数分别是100 2020-05-17 …
线性代数中的m维列向量,这个m维是m列还是m行?就是这个线性代数中的维数是列数还是行数? 2020-05-17 …
已知m大于等于2,n大于等于2,且m,n均为正整数,如果将m^n进行如下图的方式“分解”,那么有下 2020-05-20 …
设有一个m行n列的矩阵存储在二维数组A[1..M,1..n]中,将数组元素按行排列,对于A[i,j] 2020-05-26 …
那就换道题目蛤1将(2N-M)看成一个字母,把代数式(2N-M)^2-1-(2N-M)^3+2(2 2020-06-27 …
若一个数列的第m项等于这个数列的前m项的积,则称该数列为“m积数列”若正项等比数列{an}是一个“ 2020-06-30 …
已知一个无穷等差数列{An}的首项为A1,公差为d,则(1)将数列中的前m项去掉,其余各项组成一个 2020-07-20 …
一个C++约瑟夫环的问题一群人围坐一圈,每人一个密码,一开始人选一个正整数作为报数上线M,丛第一个 2020-07-29 …
已知一个等比数列{an}的首项为a1,公比为q:(1)将{an}的前m项去掉,其余各项组成的数列是 2020-07-30 …
面程序的功能是用”辗转相除法”求两个正整数的最大公约数.请填空.辗转相除法:如果有二个数m,n,将 2020-08-03 …