DropDownList操作;ListBox操作;动态创建控件;Response.Write("欢迎学习ASP.NET''!");
2008-04-18 23:04
603 查看
1 DropDownList操作;
2 ListBox操作;
3 动态创建控件;
4 Response.Write("欢迎学习ASP.NET''!");
=====================
1 DropDownList操作;(向右选择,向上移,向下移选项;)
if(DropDown1.Items.Count > 1)
{
ListItem Item = DropDown1.SelectedItem;
DropDown1.Items.Remove(Item);
String val = DropDown1.SelectedItem.Value ;
String text = DropDown1.SelectedItem.Text;
Label1.Text = val + text;
}
else
{
DropDown1.Items.Clear();
Label1.Text = "";
}
2 ListBox操作;(向右选择,向上移,向下移选项;)
private void Movebtn_Click(object sender, System.EventArgs e)
{
int Count = ListBox1.Items.Count;
int Index = 0;
for(int i=0;i<Count-1;i++)
{
ListItem Item = ListBox1.Items[Index];
if(ListBox1.Items[Index].Selected == true)
{
ListBox1.Items.Remove(Item);
ListBox2.Items.Add(Item);
Index--;
}
Index++;
}
}
private void Upbtn_Click(object sender, System.EventArgs e)
{
//若不是第一行则上移
if( ListBox1.SelectedIndex > 0 )
{
string name = ListBox1.SelectedItem.Text;
string ID = ListBox1.SelectedItem.Value;
int index = ListBox1.SelectedIndex;
ListBox1.SelectedItem.Text = ListBox1.Items[index-1].Text;
ListBox1.SelectedItem.Value = ListBox1.Items[index-1].Value;
ListBox1.Items[index-1].Text = name;
ListBox1.Items[index-1].Value = ID;
ListBox1.SelectedIndex --;
}
}
private void Downbtn_Click(object sender, System.EventArgs e)
{
//若不是最后一行则下移
if( ListBox1.SelectedIndex >= 0 && ListBox1.SelectedIndex < ListBox1.Items.Count-1 )
{
string name = ListBox1.SelectedItem.Text;
string ID = ListBox1.SelectedItem.Value;
int index = ListBox1.SelectedIndex;
ListBox1.SelectedItem.Text = ListBox1.Items[index+1].Text;
ListBox1.SelectedItem.Value = ListBox1.Items[index+1].Value;
ListBox1.Items[index+1].Text = name;
ListBox1.Items[index+1].Value = ID;
ListBox1.SelectedIndex ++;
}
}
3 动态创建控件;
private void Addbtn_Click(object sender, System.EventArgs e)
{
DropDownList DropDown = new DropDownList();
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(DropDown);
DropDown.ID="ControlID";
DropDown.Width=200;
DropDown.Items.Add(new ListItem("北京","0"));
DropDown.Items.Add(new ListItem("上海","1"));
DropDown.Items.Add(new ListItem("河北","2"));
ViewState["AddControl"] = true;
}
4 Response.Write("欢迎学习ASP.NET''!");
2 ListBox操作;
3 动态创建控件;
4 Response.Write("欢迎学习ASP.NET''!");
=====================
1 DropDownList操作;(向右选择,向上移,向下移选项;)
if(DropDown1.Items.Count > 1)
{
ListItem Item = DropDown1.SelectedItem;
DropDown1.Items.Remove(Item);
String val = DropDown1.SelectedItem.Value ;
String text = DropDown1.SelectedItem.Text;
Label1.Text = val + text;
}
else
{
DropDown1.Items.Clear();
Label1.Text = "";
}
2 ListBox操作;(向右选择,向上移,向下移选项;)
private void Movebtn_Click(object sender, System.EventArgs e)
{
int Count = ListBox1.Items.Count;
int Index = 0;
for(int i=0;i<Count-1;i++)
{
ListItem Item = ListBox1.Items[Index];
if(ListBox1.Items[Index].Selected == true)
{
ListBox1.Items.Remove(Item);
ListBox2.Items.Add(Item);
Index--;
}
Index++;
}
}
private void Upbtn_Click(object sender, System.EventArgs e)
{
//若不是第一行则上移
if( ListBox1.SelectedIndex > 0 )
{
string name = ListBox1.SelectedItem.Text;
string ID = ListBox1.SelectedItem.Value;
int index = ListBox1.SelectedIndex;
ListBox1.SelectedItem.Text = ListBox1.Items[index-1].Text;
ListBox1.SelectedItem.Value = ListBox1.Items[index-1].Value;
ListBox1.Items[index-1].Text = name;
ListBox1.Items[index-1].Value = ID;
ListBox1.SelectedIndex --;
}
}
private void Downbtn_Click(object sender, System.EventArgs e)
{
//若不是最后一行则下移
if( ListBox1.SelectedIndex >= 0 && ListBox1.SelectedIndex < ListBox1.Items.Count-1 )
{
string name = ListBox1.SelectedItem.Text;
string ID = ListBox1.SelectedItem.Value;
int index = ListBox1.SelectedIndex;
ListBox1.SelectedItem.Text = ListBox1.Items[index+1].Text;
ListBox1.SelectedItem.Value = ListBox1.Items[index+1].Value;
ListBox1.Items[index+1].Text = name;
ListBox1.Items[index+1].Value = ID;
ListBox1.SelectedIndex ++;
}
}
3 动态创建控件;
private void Addbtn_Click(object sender, System.EventArgs e)
{
DropDownList DropDown = new DropDownList();
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(DropDown);
DropDown.ID="ControlID";
DropDown.Width=200;
DropDown.Items.Add(new ListItem("北京","0"));
DropDown.Items.Add(new ListItem("上海","1"));
DropDown.Items.Add(new ListItem("河北","2"));
ViewState["AddControl"] = true;
}
4 Response.Write("欢迎学习ASP.NET''!");
相关文章推荐
- 动态创建 ASP.NET Web 服务器控件模板
- asp.net中动态创建控件添加事件
- 基于ASP.NET的Web动态控件创建
- [转]创建动态数据输入用户界面(ASP.NET 中的动态控件入门)
- [转]创建动态数据输入用户界面(ASP.NET 中的动态控件入门)
- 教学思路ASP.Net之服务器控件:三、DropDownList、ListBox、CheckBoxList、RadioButtonList控件
- 基于ASP.NET的Web动态控件创建
- ASP.NET学习笔记[4] - 无法分析从服务器在通过调用 Response.Write()
- 基于ASP.NET的Web动态控件创建
- ASP.NET AJAX Advance Tips & Tricks (2) 动态创建Rating控件不能保存ViewState的解决方案
- ASP.NET动态创建控件之绝境求生
- asp.net动态网站repeater控件使用及分页操作介绍
- 教学思路ASP.Net之服务器控件:三、DropDownList、ListBox、CheckBoxList、RadioButtonList控件
- ASP.NET动态创建控件之绝境求生第一页
- asp.net 动态创建控件和移除控件
- ASP.NET后台动态创建DropDownList中的下拉项
- [今日技术学习]利用ASP.NET 2.0创建自定义Web控件
- 基于ASP.NET的Web动态控件创建
- Asp.net 查找不到动态创建的控件之解决办法【整理】
- 总结Asp.net中Page加载PostData的具体过程 进而解决"获取动态创建的控件的PostData数据"问题