快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

澳门新葡亰平台游戏app会假吗_集报网



本文先容若何在ASP.NET中实现多页面选择的问题。其详细思路很简单:用暗藏的INPUT记着每次选择的项目,在进行数据绑准时,反省保存的值,再在DataGrid中进行选中显示。下面时完备的代码和例子:

查看例子

SelectMulti澳门新葡亰平台游戏app会假吗Pages.aspx

跨页面实现多选

'/>

' runat="server" ID="TitleShow"/>

' runat="server"/>

SelectMultiPages.aspx.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

{

///

/// SelectMultiPages 的择要阐明。

///

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 澳门新葡亰平台游戏app会假吗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澳门新葡亰平台游戏app会假吗.Current.Server.MapPath("aspx.mdb"));

OleDbDataAdapter da = new OleDbDataAdapter("Select Title, CreateD澳门新葡亰平台游戏app会假吗ate from Document",cn);

DataSet ds = new DataSet();

da.Fill(ds);

DataGrid1.DataSource= ds;

DataGrid1.DataBind();

}

private void DataGrid1_ItemDataBound(object 澳门新葡亰平台游戏app会假吗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.WordStr(",","

");

}

#region Web 窗体设计器天生的代码

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

//

InitializeComponent();

base.OnInit(e);

}

///

/// 设计器支持所需的措施 - 不要应用代码编辑器改动

/// 此措施的内容。

///

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

}

}

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

您可能还会对下面的文章感兴趣: