zoukankan
html css js c++ java
datagrid跨页实现多选
<!--
aspx的
-->
<%
@ Page EnableViewState
=
"
true
"
CodeBehind
=
"
SelectMultiPages.aspx.cs
"
Language
=
"
c#
"
AutoEventWireup
=
"
false
"
Inherits
=
"
eMeng.Exam.SelectMultiPages
"
%>
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<
HTML
>
<
HEAD
>
<
title
>
跨页面实现多选
</
title
>
<
META
http-equiv
="content-type"
content
="text/html; charset=gb2312"
>
<
style
>
*
{
}
{
FONT-SIZE
:
12PX
}
#Status
{
}
{
text-align
:
left
}
</
style
>
<
script
language
="JAVASCRIPT"
>
function
AddRemoveValues(oChk)
{
//
在处理这个地方需要注意的是:你保存的值应该具有唯一性,这样才能不会替换错误的项。
if
(oChk.checked)
SelectMultiPage.HdnSelectedValues.value
+=
"
,
"
+
oChk.value;
else
SelectMultiPage.HdnSelectedValues.value
=
SelectMultiPage.HdnSelectedValues.value.replace(
"
,
"
+
oChk.value,
""
);
}
</
script
>
</
HEAD
>
<
BODY
>
<
form
id
="SelectMultiPage"
runat
="server"
>
<
asp:datagrid
id
="DataGrid1"
HorizontalAlign
="Center"
AutoGenerateColumns
="False"
Width
="600px"
AllowPaging
="True"
runat
="server"
>
<
AlternatingItemStyle
BackColor
="#EEEEEE"
></
AlternatingItemStyle
>
<
HeaderStyle
BackColor
="#AAAADD"
Font-Bold
="True"
HorizontalAlign
="Center"
></
HeaderStyle
>
<
PagerStyle
HorizontalAlign
="Right"
Mode
="NumericPages"
Visible
="True"
></
PagerStyle
>
<
Columns
>
<
asp:TemplateColumn
HeaderText
="选择"
>
<
ItemTemplate
>
<
input
type
="checkbox"
runat
="server"
id
="chkSelect"
onclick
="AddRemoveValues(this)"
value
='<%#DataBinder.Eval(Container.DataItem,"Title")%>'/>
</ItemTemplate
>
</
asp:TemplateColumn
>
<
asp:TemplateColumn
HeaderText
="文章标题"
>
<
ItemTemplate
>
<
asp:Literal
Text
='<%#
DataBinder.Eval(Container.DataItem, "Title") %
>
' runat="server" ID="TitleShow"/>
</
ItemTemplate
>
</
asp:TemplateColumn
>
<
asp:TemplateColumn
HeaderText
="发布时间"
>
<
ItemTemplate
>
<
asp:Literal
Text
='<%#
DataBinder.Eval(Container.DataItem, "CreateDate").ToString() %
>
' runat="server"/>
</
ItemTemplate
>
</
asp:TemplateColumn
>
</
Columns
>
</
asp:datagrid
>
<
div
align
=center>
<asp:button id
="Button1"
runat
="server"
Text
="得到所选的值"
></
asp:button
>
<
div
id
="Status"
>
<
asp:label
id
="Label1"
runat
="server"
></
asp:label
>
</
div
>
<
INPUT
id
="HdnSelectedValues"
type
="hidden"
name
="HdnSelectedValues"
runat
="server"
>
</
div
>
</
form
>
</
BODY
>
</
HTML
>
//
cs的
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Data.OleDb;
using
System.Drawing;
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
namespace
eMeng.Exam
{
/**/
///
<summary>
///
SelectMultiPages 的摘要说明。
///
</summary>
public
class
SelectMultiPages : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.Button Button1;
protected
System.Web.UI.WebControls.Label Label1;
protected
System.Web.UI.HtmlControls.HtmlInputHidden HdnSelectedValues;
protected
System.Web.UI.WebControls.DataGrid DataGrid1;
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
if
(
!
Page.IsPostBack)
BindData();
}
private
void
DataGrid1_PageIndexChanged(
object
source, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex
=
e.NewPageIndex;
BindData();
}
void
BindData()
{
OleDbConnection cn
=
new
OleDbConnection(
"
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
"
+
HttpContext.Current.Server.MapPath(
"
aspx.mdb
"
));
OleDbDataAdapter da
=
new
OleDbDataAdapter(
"
Select Title, CreateDate from Document
"
,cn);
DataSet ds
=
new
DataSet();
da.Fill(ds);
DataGrid1.DataSource
=
ds;
DataGrid1.DataBind();
}
private
void
DataGrid1_ItemDataBound(
object
sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//
重新显示所选择的项目
if
(e.Item.ItemType
==
ListItemType.Item
||
e.Item.ItemType
==
ListItemType.AlternatingItem)
{
if
(HdnSelectedValues.Value.IndexOf(((Literal)e.Item.Cells[
1
].FindControl(
"
TitleShow
"
)).Text)
>=
0
)
{
HtmlInputCheckBox ChkSelected
=
(HtmlInputCheckBox)(e.Item.Cells[
0
].FindControl(
"
ChkSelect
"
));
ChkSelected.Checked
=
true
;
}
}
}
private
void
Button1_Click(
object
sender, System.EventArgs e)
{
//
为了显示的方便进行替换的
Label1.Text
=
HdnSelectedValues.Value.Replace(
"
,
"
,
"
<li>
"
);
}
Web 窗体设计器生成的代码
#region
Web 窗体设计器生成的代码
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.DataGrid1.ItemDataBound
+=
new
System.Web.UI.WebControls.DataGridItemEventHandler(
this
.DataGrid1_ItemDataBound);
this
.DataGrid1.PageIndexChanged
+=
new
System.Web.UI.WebControls.DataGridPageChangedEventHandler(
this
.DataGrid1_PageIndexChanged);
this
.Button1.Click
+=
new
System.EventHandler(
this
.Button1_Click);
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
}
}
--------------转自孟宪会------------
查看全文
相关阅读:
lsb_release -a 查询Linux系统版本
html常用标签
js判断对象是否为空
springBoot2.x 支持跨域请求配置
httpclient 上传附件实例
js 使用sessionStorage总结与实例
性能测试需求调研分析方法
jmeter压测实践
页面加载时调用js函数方法
IntelliJ IDEA 界面介绍及常用配置
原文地址:https://www.cnblogs.com/acelove/p/120254.html
最新文章
Qt开发中的实用笔记二--中文转码问题和string转换问题:
Qt开发中的实用笔记一--xml,Qpainter,Delegate:
Qt实用小技巧(转)
刷新本界面
国际音标
mvc中怎么读取htm的文件
谷歌浏览器仿触摸功能
JavaScriptConvert.SerializeObject转换出错
健康食谱
英语单词
热门文章
删除表,从0开始
百度地图,是否显示发送到手机按钮
c#中怎么求百分比
Docker常用命令
Oracle解决Ora-01653无法扩展表空间问题
重设msyql数据库root密码
判断系统是64位还是32位的bat方法
高德地图 地铁图adcode 城市代码
java正则使用方法
ubuntu 16.04启用root用户方法
Copyright © 2011-2022 走看看