早教吧作业答案频道 -->其他-->
设计一个选课程序,要求:该选课的运行界面包含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()));
}
}
看了 设计一个选课程序,要求:该选...的网友还看了以下:
一道初二的数学题-关于证平行四边行的-求过程在平行四边形ABCD中,点E,F在对角线BD上,且AE= 2020-03-30 …
求12边形的求面积公式要通俗易懂,文字说明 2020-05-23 …
已知三角形的三边长,各角的角度数未知,如何只用三边长的这一条件求出该三角形的面积呢?拜托各位大神我 2020-06-04 …
设计一个选课程序,要求:该选课的运行界面包含2个列表框,左边为已开设的课程名称,通过formloa 2020-07-21 …
急求英语翻译~~体育课要用~~大家帮忙体育课的老师要求用英语备课~~~大家帮忙啦~~一些简单的口令 2020-07-23 …
一个数学课,求助大家了几个月没上课,全都忘了,求助各位大侠,一个很简单的题,圆x²+y²=2内部( 2020-08-01 …
小明和小华一起做功课,小明对小华说:“我出一道题给你做做:一个多边形各内角都等于72°,求这个多角 2020-08-02 …
课时练习第50页复习(1)中智力冲浪题填整十数,使每条线上的三个数相加等于70三角形每条边上共三个数 2020-10-30 …
英语课老师一边讲课我们差生一边记单词能提高成绩吗如题,现在我高二,因为我没有基础,听不懂老师讲课,所 2020-11-28 …
今年高考政治按新教材还是旧教材?同学们的老师们对于这个是如何授课的??求同胞回答! 2020-11-28 …