zoukankan
html css js c++ java
个人学习代码保存:例7.ListBox小代码
前台代码:Default.aspx
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
_Default
"
%>
<!
DOCTYPE html PUBLIC
"
-//W3C//DTD XHTML 1.0 Transitional//EN
"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
"
>
<
html xmlns
=
"
http://www.w3.org/1999/xhtml
"
>
<
head runat
=
"
server
"
>
<
title
>
无标题页
</
title
>
</
head
>
<
body
>
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
div
>
<
asp:ListBox ID
=
"
ListBox1
"
runat
=
"
server
"
SelectionMode
=
"
Multiple
"
></
asp:ListBox
>&
nbsp;
<
asp:Button ID
=
"
Button2
"
runat
=
"
server
"
OnClick
=
"
Button2_Click
"
Text
=
"
>
"
/>
<
asp:Button ID
=
"
Button1
"
runat
=
"
server
"
OnClick
=
"
Button1_Click
"
Text
=
"
>>
"
/>
<
asp:ListBox ID
=
"
ListBox2
"
runat
=
"
server
"
SelectionMode
=
"
Multiple
"
></
asp:ListBox
></
div
>
</
form
>
</
body
>
</
html
>
后台代码:
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;
using
System.Data.SqlClient;
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
IsPostBack)
{
this
.ListBindData();
}
}
public
void
ListBindData()
{
string
connstr
=
ConfigurationManager.AppSettings[
"
ConnectionString
"
].ToString();
SqlConnection con
=
new
SqlConnection(connstr);
if
(con.State.Equals(ConnectionState.Closed))
{
con.Open();
}
SqlCommand cmd
=
new
SqlCommand(
"
select * from guestbook
"
,con);
SqlDataReader sdr
=
cmd.ExecuteReader(CommandBehavior.CloseConnection);
//
这是第一种方法了
//
while (sdr.Read())
//
{
//
ListBox1.Items.Add(new ListItem(sdr["title"].ToString(),sdr["id"].ToString()));
//
}
ListBox1.DataSource
=
sdr;
ListBox1.DataTextField
=
"
title
"
;
ListBox1.DataValueField
=
"
id
"
;
ListBox1.DataBind();
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
foreach
(ListItem item
in
ListBox1.Items)
{
ListBox2.Items.Add(item);
}
ListBox1.Items.Clear();
}
protected
void
Button2_Click(
object
sender, EventArgs e)
{
ListBox2.Items.Add(ListBox1.SelectedItem);
ListBox1.SelectedIndex
=
-
1
;
ListBox2.SelectedIndex
=
-
1
;
}
}
查看全文
相关阅读:
ArcGIS Server GP服务发布与测试(基础版)
【转】arcgis server site 快速恢复与重建
ArGIS Server 服务的更新
ArcMap中,如何查看当前工具是否在执行?如何将工具调到前台来执行?
【转】ArcGIS 创建切片缓存方法工具总结
ArcGIS Server 增加缓存路径
修改ArcGIS Server Account / 站点管理员的 账号、密码
ArcGIS Server 创建站点失败
ArcGIS Server,4000端口被占用
JS 中如何判断字符串类型的数字
原文地址:https://www.cnblogs.com/wbcms/p/1037554.html
最新文章
rowid
封闭解(Closed-form solution)、解析解(Analytical solution)、数值解(Numerical solution) 释义
耿建超英语语法---陈述句(1)
耿建超英语语法---虚拟语气
耿建超英语语法---被动语态
耿建超英语语法---时态+疑问句
Microsoft Visio绘图
耿建超英语语法---情态动词
总结|吴恩达深度学习
理解CNN中的通道 channel
热门文章
卷积、卷积核的维数、尺寸
linux mysql数据库的主从配置
算法(可怜的小猪)
算法(四数相加)
算法(判断字符串是否可以由它的一个子串重复多次构成)
进程间通信
socket的通信
Linux IO模式及 select、poll、epoll详解
php单例模式的设计与实现
往sde中导入要素类报错000732
Copyright © 2011-2022 走看看