All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
.Net中常见问题及解决方法归类_[Asp.Net教程]
XSL教程:匹配模式的学习_[XML教程]
用DHTML中的Popup,Object跨框架显示菜单_JavaScript技术_编程技术
用sql存储过程实现前台标题变色_[SQL Server教程]
PHP读取汉字点阵数据_[PHP教程]
利用单元测试在每个层上对PHP代码进行检查_php资料_编程技术
SQL日志文件长度过大的处理方法_[SQL,Server教程]
asp.net项目运行的权限问题_.net资料_编程技术
php实现下载功能_php资料_编程技术
delphi设置映射模式
Reading number is top 10 pictures
Thrilling English baby
29 the belle stars after bath figure4
BingBingFan apple dew point photo gallery4
The real super beauty12
Average female college students1
Lewd,it is too lewd.
Japanese snow monkeys in the hot spring to keep warm, close their eyes to enjoy
各种囧况!玩游戏最不喜欢出现的十件事(点评)
随便发几张图
The money of more than 100 countries and regions2
Download software ranking
Sora aoi, the nurse, uniform ,nursing assistant
WebService在.NET中的实战应用教学视频 → 第4集
实战黑客不求人
Unix video tutorial20
Boxer vs Yellow2
Boxer's Top ten classic battle2
塘西风月痕
Boxer Classic video2
linux安装大全
jdk1.6 for windows
delv published in(发表于) 2014/1/23 3:14:00 Edit(编辑)
利用GridView显示主细表并添加删除、打开、关闭功能(续)_[Asp.Net教程]

利用GridView显示主细表并添加删除、打开、关闭功能(续)_[Asp.Net教程]

利用GridView显示主细表并添加删除、打开、关闭功能(续)_[Asp.Net教程]

本文是利用GridView显示主细表并添加打开、关闭功能的扩展。


有网友在论坛上询问:如何在使用GridView显示主细表时添加删除功能?其实,如果单个GridView能够实现删除对话,N个GridView嵌套也没有任何问题。下面就将例子粘贴如下,望各位需要的朋友仔细揣摩一下,道理很简单的:)


查看例子


aspx


<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>





利用GridView显示主细表并添加打开、关闭功能







BorderWidth="1" OnRowDataBound="MasterGridView_RowDataBound" DataKeyNames="id"
ShowHeader="false">




float: left">
栏目名称:<%#Eval("Title") %>onclick="ShowHidden('<%#Eval("id") %>',event)">隐藏


">
HorizontalAlign="left" DataKeyNames="id" AutoGenerateDeleteButton="true" OnRowCommand="DetailGridView_RowCommand"
OnRowDeleting="DetailGridView_RowDeleting" Width="720px">




/read.aspx">
<%#Eval("Title") %>
[<%# Eval("HitCount") %>]


HeaderStyle-Width="100px" ItemStyle-HorizontalAlign="Center" />












C#


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Web.UI.HtmlControls;


public partial class Default2 : System.Web.UI.Page
{
string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\aspxWeb.mdb;Persist Security Info=True";
OleDbConnection cn1;



protected void Page_Load( object sender, EventArgs e )
{
if (!Page.IsPostBack)
{
OleDbConnection cn = new OleDbConnection(ConnectionString);
cn.Open();
cn1 = new OleDbConnection(ConnectionString);
cn1.Open();
OleDbCommand cmd = new OleDbCommand("select * from [Subject]", cn);
OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
MasterGridView.DataSource = dr;
MasterGridView.DataBind();
dr.Close();
cmd.Dispose();
cn.Dispose();
cn1.Dispose();
cn = cn1 = null;
}
}
protected void MasterGridView_RowDataBound( object sender, GridViewRowEventArgs e )
{
if (e.Row.RowType == DataControlRowType.DataRow)
{


GridView oGridView = (GridView)e.Row.FindControl("DetailGridView");
if (oGridView != null)
{
OleDbCommand cmd = new OleDbCommand("select top 10 * from Document Where pid = " + MasterGridView.DataKeys[e.Row.RowIndex].Value, cn1);
OleDbDataReader dr1 = cmd.ExecuteReader();
oGridView.DataSource = dr1;
oGridView.DataBind();
dr1.Close();
cmd.Dispose();
}
}
}


protected void DetailGridView_RowDeleting( object sender, GridViewDeleteEventArgs e )
{
GridView a = (GridView)sender;
Response.Write("您要删除的记录是:" + a.DataKeys[e.RowIndex].Value.ToString() + "&nbsp;&nbsp;&nbsp;&nbsp;TODO:执行删除动作");
// TODO:执行删除动作
}
protected void DetailGridView_RowCommand( object sender, GridViewCommandEventArgs e )
{


}
}
注意:EnableViewState="true" 是必须的。



来源:孟宪会之精彩世界







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.