无刷新实现主从表以及从表的隐藏和现实

ASP.NET GridView嵌套Repeater示例
本文介绍了一个使用ASP.NET实现的GridView中嵌套Repeater的例子,并展示了如何通过展开和折叠行来查看详细信息。该示例还包含了一个用于切换详细视图的JavaScript函数。

HTML Code:

 

ContractedBlock.gifExpandedBlockStart.gif代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="tlrrList.aspx.cs" Inherits="byd.EquipmentManager.tlrrList" %>

<!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>
<script type="text/javascript" src="../Scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
var showDiv=function(img){
var td=img.parentNode;
var tr=td.parentNode;
var thead=tr.parentNode;
var tbody=thead.nextSibling;
var tbodystyle=tbody.style;
var picName=img.src;
picName
=picName.substring(picName.lastIndexOf("/")+1);

img.src
=picName.toLowerCase()=="close.gif"?"../Images/open.gif":"../Images/close.gif";
tbodystyle.display
=tbodystyle.display=="none"?"":"none";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table cellpadding="0" cellspacing="0" border="1" width="100%;">
<tr>
<td align="right"><a href="tlrr.aspx">New TLRR</a></td>
</tr>
<tr><td>
<asp:GridView ID="gvList" runat="server" AutoGenerateColumns="False" Width="100%"
CellPadding
="4" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" border="1" width="100%;">
<thead>
<tr>
<td style="width:15%" align="center">msid</td>
<td style="width:15%" align="center">session id</td>
<td style="width:15%" align="center">request_id</td>
<td style="width:15%" align="center">time</td>
<td style="width:15%" align="center">status</td>
<td style="width:15%" align="center">action</td>
</tr>
</thead>
</table>
</HeaderTemplate>
<ItemTemplate>
<table cellpadding="0" cellspacing="0" border="1" width="100%">
<thead>
<tr>
<td>
<img onclick="showDiv(this)" style="cursor:hand" src="../Images/open.gif" alt="" />
<%#Eval("msid_mdn")%>
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<asp:Repeater ID="rptDetail" runat="server" DataSource='<%# ((System.Data.DataRowView)Container.DataItem).CreateChildView("tableRelation") %>'
DataMember="msid_mdn" OnItemCommand="rptDetail_ItemCommand">
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" border="1" width="100%;">
<tr>
<td colspan="5" style="height:5px;"></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width:15%" align="center"><asp:Label runat="server" ID="msid" Text='<%# DataBinder.Eval(Container.DataItem,"msid")%>'></asp:Label></td>
<td style="width:15%" align="center"><%# DataBinder.Eval(Container.DataItem,"session_id")%></td>
<td style="width:15%" align="center"><%# DataBinder.Eval(Container.DataItem,"request_id")%></td>
<td style="width:15%" align="center"><%# DataBinder.Eval(Container.DataItem,"time")%></td>
<td style="width:15%" align="center">
<asp:DropDownList ID="ddlStatus" runat="server">
<asp:ListItem Text="select" Value="1"></asp:ListItem>
<asp:ListItem Text="view" Value="2"></asp:ListItem>
<asp:ListItem Text="fellow" Value="3"></asp:ListItem>
</asp:DropDownList>&nbsp;&nbsp;<asp:LinkButton ID="lbnGO" runat="server" CommandName="GO" Font-Underline="false">GO</asp:LinkButton>
</td>
<td style="width:15%" align="center"></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</tbody>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</td></tr>
</table>
</form>
</body>
</html>

CS Code:

 

ContractedBlock.gifExpandedBlockStart.gif代码
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.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataAccess;

namespace byd.EquipmentManager
{
public partial class tlrrList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}

private void Bind()
{
DataSet ds
= new DataSet();
using (EntityDAO edo = new EntityDAO())
{
ds
= edo.Get_TLRRList();

DataColumn father
= ds.Tables[0].Columns["msid_mdn"];
DataColumn child
= ds.Tables[1].Columns["msid"];
DataRelation tableRelation
= new DataRelation("tableRelation", father, child, false);
ds.Relations.Add(tableRelation);

gvList.DataSource
= ds.Tables[0];
gvList.DataBind();
}
}

protected void rptDetail_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "GO")
{
DropDownList ddl
= (DropDownList)e.Item.FindControl("ddlStatus");
string val = ddl.SelectedValue;
Label lbl
= (Label)e.Item.FindControl("msid");
string msid = lbl.Text.ToString();
if (val == "1")
{
Response.Redirect(
"tlrr.aspx?ddlStatus=" + msid);
}
}
}
}
}

 

转载于:https://www.cnblogs.com/ssyang/archive/2010/06/04/1751671.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值