using
System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{//演示一的事件
Label1.Text = ListBox1.SelectedValue.ToString();//把Label的文字赋值为列表框中被选中的值
if (ListBox1.SelectedValue == "洪川医药")//当选定项的值等于 洪川医药的时候就转到hc115.com 去
{
Response.Redirect("http://www.hc115.com/qyml/");
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{//懒得用按纽了,演示二的添加列表项动作
ListBox2.Items.Add(TextBox1.Text);//给列表项添加一项
Button1.Text = "移除";//防止有人先在点击了移除按纽,所以下面做了处理,这里如果是添加了,当然按纽就还原了撒
Button1.Enabled = true;
Button2.Text = "清空";//防止有人先在点击了移除按纽,所以下面做了处理,这里如果是添加了,当然按纽就还原了撒
Button2.Enabled = true;
}
protected void Button1_Click(object sender, EventArgs e)
{//移出事件
if (ListBox2.Items.Count > 0)//如果列表项的索引值大与0
{
ListBox2.Items.Remove(ListBox2.SelectedItem);//就移除指定项
}
else
{//否则
Button1.Text = "你疯了哇,都没有东西,你叫我删什么,有本事你自己去删嘛";
Button1.Enabled = false;
}
}
protected void Button2_Click(object sender, EventArgs e)
{//原理基本同上
if (ListBox2.Items.Count > 0)//如果列表项的索引值大与0
{
ListBox2.Items.Clear();//就清空所有项
}
else
{//否则
Button2.Text = "你疯了哇,都没有东西,你叫我清空什么,有本事你自己去清空嘛";
Button2.Enabled = false;
}
}
protected void ListBox4_SelectedIndexChanged(object sender, EventArgs e)
{//两级联动菜单事件
switch (ListBox4.SelectedValue)//判断一级列表中被选中的值
{
case "洪川医药"://如果是这个,那二级就添加下面这些
ListBox5.Items.Add("医院评价");
ListBox5.Items.Add("医院名录");
ListBox5.Items.Add("假药暴光");
ListBox5.Items.Add("医药黑幕");
break;
case "天轰穿的博客"://如果是这个,那二级就添加下面这些
ListBox5.Items.Add("Vs2005系列控件");
ListBox5.Items.Add("学习笔记");
break;
}
}
protected void Button7_Click(object sender, EventArgs e)
{//向上下移动一条 事件
if (((Button)sender).CommandName == "up" && ListBox6.SelectedIndex > 0 || ((Button)sender).CommandName == "down" && ListBox6.SelectedIndex < ListBox6.Items.Count - 1)
{ //判断传来的命令名必须是 up并且所选条目的索引必须大于0 或者 down并且所选条目必须小于最大项
int index;//为了减少代码,这里做一个对变量的判断,以后就直接调用变量,
if (((Button)sender).CommandName == "up")
{
index = -1;//以后的索引本来就是在当前的条目上加一或者减,所以这个方法很不错
}
else
{
index = 1;
}
ListItem lt = new ListItem(ListBox6.SelectedItem.Text,ListBox6.SelectedValue);//将当前条目的文本以及值都保存到一个临时变量里面
ListBox6.Items[ListBox6.SelectedIndex].Text = ListBox6.Items[ListBox6.SelectedIndex + index].Text;//被选中项的值等于上一条或者下一条的值
ListBox6.Items[ListBox6.SelectedIndex].Value = ListBox6.Items[ListBox6.SelectedIndex + index].Value;//被选中项的值等于上一条或者下一条的值
ListBox6.Items[ListBox6.SelectedIndex + index].Text = lt.Text;//把被选中项的上一条或者下一条的值用临时变量中的取代
ListBox6.Items[ListBox6.SelectedIndex + index].Value = lt.Value;//把被选中项的上一条或者下一条的值用临时变量中的取代
ListBox6.SelectedIndex = ListBox6.SelectedIndex + index;//把鼠标指针放到移动后的那条上
}
}
protected void Button4_Click(object sender, EventArgs e)
{//移至首条
ListBox6.SelectedIndex = 0;//将被选中项的索引设置为0就可以啦,
}
protected void Button9_Click(object sender, EventArgs e)
{//移至尾条
ListBox6.SelectedIndex = ListBox6.Items.Count-1;//因为C#里面默认的索引都是从0开始,所以最大项必须减一才是真实的
}
protected void Button5_Click(object sender, EventArgs e)
{//上一条
ListBox6.SelectedIndex = ListBox6.SelectedIndex - 1;//用当前被选中的索引去减一
}
protected void Button6_Click(object sender, EventArgs e)
{//下一条
ListBox6.SelectedIndex = ListBox6.SelectedIndex + 1;//用当前被选中的索引去加一
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{//演示一的事件
Label1.Text = ListBox1.SelectedValue.ToString();//把Label的文字赋值为列表框中被选中的值
if (ListBox1.SelectedValue == "洪川医药")//当选定项的值等于 洪川医药的时候就转到hc115.com 去
{
Response.Redirect("http://www.hc115.com/qyml/");
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{//懒得用按纽了,演示二的添加列表项动作
ListBox2.Items.Add(TextBox1.Text);//给列表项添加一项
Button1.Text = "移除";//防止有人先在点击了移除按纽,所以下面做了处理,这里如果是添加了,当然按纽就还原了撒
Button1.Enabled = true;
Button2.Text = "清空";//防止有人先在点击了移除按纽,所以下面做了处理,这里如果是添加了,当然按纽就还原了撒
Button2.Enabled = true;
}
protected void Button1_Click(object sender, EventArgs e)
{//移出事件
if (ListBox2.Items.Count > 0)//如果列表项的索引值大与0
{
ListBox2.Items.Remove(ListBox2.SelectedItem);//就移除指定项
}
else
{//否则
Button1.Text = "你疯了哇,都没有东西,你叫我删什么,有本事你自己去删嘛";
Button1.Enabled = false;
}
}
protected void Button2_Click(object sender, EventArgs e)
{//原理基本同上
if (ListBox2.Items.Count > 0)//如果列表项的索引值大与0
{
ListBox2.Items.Clear();//就清空所有项
}
else
{//否则
Button2.Text = "你疯了哇,都没有东西,你叫我清空什么,有本事你自己去清空嘛";
Button2.Enabled = false;
}
}
protected void ListBox4_SelectedIndexChanged(object sender, EventArgs e)
{//两级联动菜单事件
switch (ListBox4.SelectedValue)//判断一级列表中被选中的值
{
case "洪川医药"://如果是这个,那二级就添加下面这些
ListBox5.Items.Add("医院评价");
ListBox5.Items.Add("医院名录");
ListBox5.Items.Add("假药暴光");
ListBox5.Items.Add("医药黑幕");
break;
case "天轰穿的博客"://如果是这个,那二级就添加下面这些
ListBox5.Items.Add("Vs2005系列控件");
ListBox5.Items.Add("学习笔记");
break;
}
}
protected void Button7_Click(object sender, EventArgs e)
{//向上下移动一条 事件
if (((Button)sender).CommandName == "up" && ListBox6.SelectedIndex > 0 || ((Button)sender).CommandName == "down" && ListBox6.SelectedIndex < ListBox6.Items.Count - 1)
{ //判断传来的命令名必须是 up并且所选条目的索引必须大于0 或者 down并且所选条目必须小于最大项
int index;//为了减少代码,这里做一个对变量的判断,以后就直接调用变量,
if (((Button)sender).CommandName == "up")
{
index = -1;//以后的索引本来就是在当前的条目上加一或者减,所以这个方法很不错
}
else
{
index = 1;
}
ListItem lt = new ListItem(ListBox6.SelectedItem.Text,ListBox6.SelectedValue);//将当前条目的文本以及值都保存到一个临时变量里面
ListBox6.Items[ListBox6.SelectedIndex].Text = ListBox6.Items[ListBox6.SelectedIndex + index].Text;//被选中项的值等于上一条或者下一条的值
ListBox6.Items[ListBox6.SelectedIndex].Value = ListBox6.Items[ListBox6.SelectedIndex + index].Value;//被选中项的值等于上一条或者下一条的值
ListBox6.Items[ListBox6.SelectedIndex + index].Text = lt.Text;//把被选中项的上一条或者下一条的值用临时变量中的取代
ListBox6.Items[ListBox6.SelectedIndex + index].Value = lt.Value;//把被选中项的上一条或者下一条的值用临时变量中的取代
ListBox6.SelectedIndex = ListBox6.SelectedIndex + index;//把鼠标指针放到移动后的那条上
}
}
protected void Button4_Click(object sender, EventArgs e)
{//移至首条
ListBox6.SelectedIndex = 0;//将被选中项的索引设置为0就可以啦,
}
protected void Button9_Click(object sender, EventArgs e)
{//移至尾条
ListBox6.SelectedIndex = ListBox6.Items.Count-1;//因为C#里面默认的索引都是从0开始,所以最大项必须减一才是真实的
}
protected void Button5_Click(object sender, EventArgs e)
{//上一条
ListBox6.SelectedIndex = ListBox6.SelectedIndex - 1;//用当前被选中的索引去减一
}
protected void Button6_Click(object sender, EventArgs e)
{//下一条
ListBox6.SelectedIndex = ListBox6.SelectedIndex + 1;//用当前被选中的索引去加一
}
}