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
;
}
}
查看全文
相关阅读:
jquer 的简输出
jQuery 效果999动画 延迟
Windows Mobile开发环境搭建指南
使用.NET 框架压缩版开发Windows Mobile 2003 for Smartphone
SmartPhone 2003 手机编程实战之一[转载]
Smartphone移动开发—自己开发一个天气预报服务 (转载)
101个微软提供的Visual Studio 2005示例
基于 Windows Mobile 的 Pocket PC 和 Smartphone 的开发工具简介
手机耐用绝对秘密方法
Cheese 游戏编程:第 4 部分 (转自MSDN)
原文地址:https://www.cnblogs.com/wbcms/p/1037554.html
最新文章
Enum枚举
父类引用指向子类对象
使用Eclipse的debug调试功能 写给刚走出校门的童鞋
ubuntu12.04安装中文输入法(ibus)和开机自动启动ibus应用
Eclipse中使用JUnit4单元测试 初级 中级 高级
start with ... connect by prior ...
BigInteger使用总结(也是不可变的)
Eclipse插件之subclipse,jdgui
hashcode和equals方法详细解析, hashmap对于hashcode方法的使用
CustomAction Basics in SharePoint
热门文章
用户控件webpart开发
Intro to WSPBuilder
Custom Actions in WSS 3 / MOSS 2007 Part 1
add a custom action to a SharePoint list actions menu for a specific list or content type
sharepoint 工作流 相关
discussion 列表及头像
sharepoint 用户和组
Sharepoint Custom Action Element Definition
sharepoint 讨论板编程
html 去li的原点和a的下划线
Copyright © 2011-2022 走看看