asp.net中listview下嵌套gridview
最近在上软件工程实践课程,想做一个类似于QQ空间或者朋友圈一样的效果。即显示所有好友发送的动态以及动态下回复的信息。
自己YY了一种方法,一开始以为不能达到效果,研究了2个小时终于实现了,感觉效果还是很棒棒的,拿来分享一下。神犇请绕道吧~~
listview可以自己排版布局,我们用listview来显示动态发送者的头像,昵称以及发送时间。
那回复怎么办呢?
gridview的布局与回复较像,效果也比较好。那就用gridview来做回复部分好了。
主要思路就是上图,黑色的由listview显示,红色的回复部分由gridview显示。listview会获取动态信息的ID:<%# Eval("DynamicID") %>,根据这个ID,在gridview中设置好属性,去寻找哪些评论是评论这条动态信息ID的,select出来即可。
效果大约是这样的:
嵌套布局的代码大致是这样子的:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true"
CodeBehind="Dynamic.aspx.cs" Inherits="Platform.学生.Dynamic" Title="大学生学习交友平台 - 动态消息" MaintainScrollPositionOnPostback="true" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style>
body{font-family:"微软雅黑"}
</style> <style type="text/css">
.style3
{
width: %;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table class="style3">
<tr>
<td>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="StudentID,DynamicID"
DataSourceID="SqlDataSource1" onitemcommand="ListView1_ItemCommand">
<ItemTemplate>
<table class="style3">
<tr>
<td rowspan="" width="">
<img alt="" src="<%# Eval("StudentPhoto") %>" height="" width="" />
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("StudentName") %>'></asp:Label>
</td>
<td>
<asp:Label Visible="false" ID="Label0" runat="server" Text='<%# Eval("DynamicID") %>'></asp:Label>
</td> </tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("DynamicDate") %>'></asp:Label>
</td>
<br>
</tr> <tr>
<td colspan="">
<asp:Label ID="Label3" runat="server" Text='<%# Eval("DynamicText") %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="">
<img alt="" src="<%# Eval("DynamicPhoto") %>" />
</td>
</tr>
<tr>
<td colspan="">
<asp:Label ID="Label4" runat="server" Text="有"></asp:Label>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("DynamicZan") %>'></asp:Label>
<asp:Label ID="Label6" runat="server" Text="人觉得很赞!"></asp:Label>
<asp:Button ID="ButtonZan" runat="server" Text="赞!" CommandArgument="<%#Container.DataItemIndex %>" CommandName="ButtonZan"/>
</td>
</tr>
<tr>
<td colspan="">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CommentID,StudentID1"
DataSourceID="SqlDataSource2" CellPadding="" ForeColor="#333333" GridLines="None"
Width="600px" ShowHeader="false">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="StudentName" HeaderText="StudentName" SortExpression="StudentName" />
<asp:BoundField DataField="CommentText" HeaderText="CommentText" SortExpression="CommentText" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<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>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DataBase %>"
SelectCommand="SELECT *
FROM Comment as C JOIN Student as S ON S.StudentID = C.StudentID
WHERE ([DynamicID] = @DynamicID)">
<SelectParameters>
<asp:ControlParameter ControlID="Label0" Name="DynamicID" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBoxReply" runat="server" ></asp:TextBox>
<asp:Button ID="ButtonReply" runat="server" Text="留言" CommandArgument="<%#Container.DataItemIndex %>" CommandName="ButtonReply"/>
</td>
<td>
</td>
</tr>
</table>
<br />
<br />
</span>
</ItemTemplate>
<EmptyDataTemplate>
<span>未返回数据。</span>
</EmptyDataTemplate>
<InsertItemTemplate>
<span style="">StudentID:
<asp:TextBox ID="StudentIDTextBox" runat="server" Text='<%# Bind("StudentID") %>' />
<br />
StudentPwd:
<asp:TextBox ID="StudentPwdTextBox" runat="server" Text='<%# Bind("StudentPwd") %>' />
<br />
StudentName:
<asp:TextBox ID="StudentNameTextBox" runat="server" Text='<%# Bind("StudentName") %>' />
<br />
StudentSex:
<asp:TextBox ID="StudentSexTextBox" runat="server" Text='<%# Bind("StudentSex") %>' />
<br />
StudentAge:
<asp:TextBox ID="StudentAgeTextBox" runat="server" Text='<%# Bind("StudentAge") %>' />
<br />
StudentBirthday:
<asp:TextBox ID="StudentBirthdayTextBox" runat="server" Text='<%# Bind("StudentBirthday") %>' />
<br />
StudentConstellation:
<asp:TextBox ID="StudentConstellationTextBox" runat="server" Text='<%# Bind("StudentConstellation") %>' />
<br />
StudentCollege:
<asp:TextBox ID="StudentCollegeTextBox" runat="server" Text='<%# Bind("StudentCollege") %>' />
<br />
StudentMajor:
<asp:TextBox ID="StudentMajorTextBox" runat="server" Text='<%# Bind("StudentMajor") %>' />
<br />
StudentHobby:
<asp:TextBox ID="StudentHobbyTextBox" runat="server" Text='<%# Bind("StudentHobby") %>' />
<br />
StudentEmail:
<asp:TextBox ID="StudentEmailTextBox" runat="server" Text='<%# Bind("StudentEmail") %>' />
<br />
StudentTEL:
<asp:TextBox ID="StudentTELTextBox" runat="server" Text='<%# Bind("StudentTEL") %>' />
<br />
StudentAddress:
<asp:TextBox ID="StudentAddressTextBox" runat="server" Text='<%# Bind("StudentAddress") %>' />
<br />
StudentSingle:
<asp:TextBox ID="StudentSingleTextBox" runat="server" Text='<%# Bind("StudentSingle") %>' />
<br />
StudentPhoto:
<asp:TextBox ID="StudentPhotoTextBox" runat="server" Text='<%# Bind("StudentPhoto") %>' />
<br />
StudentIntroduction:
<asp:TextBox ID="StudentIntroductionTextBox" runat="server" Text='<%# Bind("StudentIntroduction") %>' />
<br />
DynamicID:
<asp:TextBox ID="DynamicIDTextBox" runat="server" Text='<%# Bind("DynamicID") %>' />
<br />
StudentID1:
<asp:TextBox ID="StudentID1TextBox" runat="server" Text='<%# Bind("StudentID1") %>' />
<br />
DynamicText:
<asp:TextBox ID="DynamicTextTextBox" runat="server" Text='<%# Bind("DynamicText") %>' />
<br />
DynamicDate:
<asp:TextBox ID="DynamicDateTextBox" runat="server" Text='<%# Bind("DynamicDate") %>' />
<br />
DynamicPhoto:
<asp:TextBox ID="DynamicPhotoTextBox" runat="server" Text='<%# Bind("DynamicPhoto") %>' />
<br />
DynamicZan:
<asp:TextBox ID="DynamicZanTextBox" runat="server" Text='<%# Bind("DynamicZan") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="插入" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="清除" />
<br />
<br />
</span>
</InsertItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style="">
<span id="itemPlaceholder" runat="server" />
</div>
<div style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False"
ShowPreviousPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False"
ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
<EditItemTemplate>
<span style="">StudentID:
<asp:Label ID="StudentIDLabel1" runat="server" Text='<%# Eval("StudentID") %>' />
<br />
StudentPwd:
<asp:TextBox ID="StudentPwdTextBox" runat="server" Text='<%# Bind("StudentPwd") %>' />
<br />
StudentName:
<asp:TextBox ID="StudentNameTextBox" runat="server" Text='<%# Bind("StudentName") %>' />
<br />
StudentSex:
<asp:TextBox ID="StudentSexTextBox" runat="server" Text='<%# Bind("StudentSex") %>' />
<br />
StudentAge:
<asp:TextBox ID="StudentAgeTextBox" runat="server" Text='<%# Bind("StudentAge") %>' />
<br />
StudentBirthday:
<asp:TextBox ID="StudentBirthdayTextBox" runat="server" Text='<%# Bind("StudentBirthday") %>' />
<br />
StudentConstellation:
<asp:TextBox ID="StudentConstellationTextBox" runat="server" Text='<%# Bind("StudentConstellation") %>' />
<br />
StudentCollege:
<asp:TextBox ID="StudentCollegeTextBox" runat="server" Text='<%# Bind("StudentCollege") %>' />
<br />
StudentMajor:
<asp:TextBox ID="StudentMajorTextBox" runat="server" Text='<%# Bind("StudentMajor") %>' />
<br />
StudentHobby:
<asp:TextBox ID="StudentHobbyTextBox" runat="server" Text='<%# Bind("StudentHobby") %>' />
<br />
StudentEmail:
<asp:TextBox ID="StudentEmailTextBox" runat="server" Text='<%# Bind("StudentEmail") %>' />
<br />
StudentTEL:
<asp:TextBox ID="StudentTELTextBox" runat="server" Text='<%# Bind("StudentTEL") %>' />
<br />
StudentAddress:
<asp:TextBox ID="StudentAddressTextBox" runat="server" Text='<%# Bind("StudentAddress") %>' />
<br />
StudentSingle:
<asp:TextBox ID="StudentSingleTextBox" runat="server" Text='<%# Bind("StudentSingle") %>' />
<br />
StudentPhoto:
<asp:TextBox ID="StudentPhotoTextBox" runat="server" Text='<%# Bind("StudentPhoto") %>' />
<br />
StudentIntroduction:
<asp:TextBox ID="StudentIntroductionTextBox" runat="server" Text='<%# Bind("StudentIntroduction") %>' />
<br />
DynamicID:
<asp:Label ID="DynamicIDLabel1" runat="server" Text='<%# Eval("DynamicID") %>' />
<br />
StudentID1:
<asp:TextBox ID="StudentID1TextBox" runat="server" Text='<%# Bind("StudentID1") %>' />
<br />
DynamicText:
<asp:TextBox ID="DynamicTextTextBox" runat="server" Text='<%# Bind("DynamicText") %>' />
<br />
DynamicDate:
<asp:TextBox ID="DynamicDateTextBox" runat="server" Text='<%# Bind("DynamicDate") %>' />
<br />
DynamicPhoto:
<asp:TextBox ID="DynamicPhotoTextBox" runat="server" Text='<%# Bind("DynamicPhoto") %>' />
<br />
DynamicZan:
<asp:TextBox ID="DynamicZanTextBox" runat="server" Text='<%# Bind("DynamicZan") %>' />
<br />
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="更新" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="取消" />
<br />
<br />
</span>
</EditItemTemplate>
<SelectedItemTemplate>
<span style="">StudentID:
<asp:Label ID="StudentIDLabel" runat="server" Text='<%# Eval("StudentID") %>' />
<br />
StudentPwd:
<asp:Label ID="StudentPwdLabel" runat="server" Text='<%# Eval("StudentPwd") %>' />
<br />
StudentName:
<asp:Label ID="StudentNameLabel" runat="server" Text='<%# Eval("StudentName") %>' />
<br />
StudentSex:
<asp:Label ID="StudentSexLabel" runat="server" Text='<%# Eval("StudentSex") %>' />
<br />
StudentAge:
<asp:Label ID="StudentAgeLabel" runat="server" Text='<%# Eval("StudentAge") %>' />
<br />
StudentBirthday:
<asp:Label ID="StudentBirthdayLabel" runat="server" Text='<%# Eval("StudentBirthday") %>' />
<br />
StudentConstellation:
<asp:Label ID="StudentConstellationLabel" runat="server" Text='<%# Eval("StudentConstellation") %>' />
<br />
StudentCollege:
<asp:Label ID="StudentCollegeLabel" runat="server" Text='<%# Eval("StudentCollege") %>' />
<br />
StudentMajor:
<asp:Label ID="StudentMajorLabel" runat="server" Text='<%# Eval("StudentMajor") %>' />
<br />
StudentHobby:
<asp:Label ID="StudentHobbyLabel" runat="server" Text='<%# Eval("StudentHobby") %>' />
<br />
StudentEmail:
<asp:Label ID="StudentEmailLabel" runat="server" Text='<%# Eval("StudentEmail") %>' />
<br />
StudentTEL:
<asp:Label ID="StudentTELLabel" runat="server" Text='<%# Eval("StudentTEL") %>' />
<br />
StudentAddress:
<asp:Label ID="StudentAddressLabel" runat="server" Text='<%# Eval("StudentAddress") %>' />
<br />
StudentSingle:
<asp:Label ID="StudentSingleLabel" runat="server" Text='<%# Eval("StudentSingle") %>' />
<br />
StudentPhoto:
<asp:Label ID="StudentPhotoLabel" runat="server" Text='<%# Eval("StudentPhoto") %>' />
<br />
StudentIntroduction:
<asp:Label ID="StudentIntroductionLabel" runat="server" Text='<%# Eval("StudentIntroduction") %>' />
<br />
DynamicID:
<asp:Label ID="DynamicIDLabel" runat="server" Text='<%# Eval("DynamicID") %>' />
<br />
StudentID1:
<asp:Label ID="StudentID1Label" runat="server" Text='<%# Eval("StudentID1") %>' />
<br />
DynamicText:
<asp:Label ID="DynamicTextLabel" runat="server" Text='<%# Eval("DynamicText") %>' />
<br />
DynamicDate:
<asp:Label ID="DynamicDateLabel" runat="server" Text='<%# Eval("DynamicDate") %>' />
<br />
DynamicPhoto:
<asp:Label ID="DynamicPhotoLabel" runat="server" Text='<%# Eval("DynamicPhoto") %>' />
<br />
DynamicZan:
<asp:Label ID="DynamicZanLabel" runat="server" Text='<%# Eval("DynamicZan") %>' />
<br />
<br />
</span>
</SelectedItemTemplate>
</asp:ListView>
</td>
</tr>
<tr>
<td>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DataBase %>"
SelectCommand="SELECT *
FROM Student as S JOIN DynamicInformation as D on S.StudentID = D.StudentID order by D.DynamicDate desc"></asp:SqlDataSource>
</td>
</tr>
</table>
</asp:Content>
asp.net中listview下嵌套gridview的更多相关文章
- ScrollView下嵌套GridView或ListView默认不在顶部的解决方法
自定义ScrollView重写下面的方法 /* ScrollView下嵌套GridView或ListView默认不在顶部的解决方法*/ @Override protected int computeS ...
- android 之 ListView 里面嵌套 GridView 遇到的问题及其解决方法。
我们直接入主题.所有问题例子请参照下图 1,怎样使图片具有点击事件? 答: 解决方法: 在你的BaseAdapter里面不要设置下面这三个东西,然后再设置GridView的onItemClick. g ...
- ListView 里面嵌套 GridView 遇到的问题及其解决方法。
我们直接入主题.所有问题例子请参照下图 1,怎样使图片具有点击事件? 答: 解决方法: 在你的BaseAdapter里面不要设置下面这三个东西,然后再设置GridView的onItemClick. g ...
- 【转载】Android中ListView下拉刷新的实现
在网上看到一个下拉刷新的例子,很的很棒,转载和更多的人分享学习 原文:http://blog.csdn.net/loongggdroid/article/details/9385535 ListVie ...
- Android中ListView下拉刷新的实现
ListView中的下拉刷新是非常常见的,也是经常使用的,看到有很多同学想要,那我就整理一下,供大家参考.那我就不解释,直接上代码了. 这里需要自己重写一下ListView,重写代码如下: packa ...
- asp.net中父子页面通过gridview中的按钮事件进行回传值的问题
这两天写BS程序,遇到父子页面传值的问题,以前没写过web系统,用了几天时间才将问题解决,总结下记录下来: 问题描述: 父页面A中有一个gridview,每行6个列,有5列中均有一个按钮,单击按钮,会 ...
- android中listView下拉刷新
Android的ListView是应用最广的一个组件,功能强大,扩展性灵活(不局限于ListView本身一个类),前面的文章有介绍分组,拖拽,3D立体,游标,圆角,而今天我们要介绍的是另外一个扩展Li ...
- Asp.net中,点击GridView表头实现数据的排序
一.实现该功能的基本工作. 1. 先添加一个GridView,取名为gvData. 2. 设置该控件的属性: 操作步骤如下 设置属性: 这4个属性,还要设置该控件AllowSorting=&quo ...
- ListView下拉刷新、上拉载入更多之封装改进
在Android中ListView下拉刷新.上拉载入更多示例一文中,Maxwin兄给出的控件比较强大,前面有详细介绍,但是有个不足就是,里面使用了一些资源文件,包括图片,String,layout,这 ...
随机推荐
- android 通过wifi 热点实现手机摄像头数据共享(转)
原文地址:http://blog.csdn.net/sinat_35845281/article/details/52674946 最近想搞一个新奇的玩意儿~~~ 最近一直在在学习通过两个Androi ...
- Django之强大的Form功能
转载: http://www.cnblogs.com/0820-zq/p/5807980.html Form Form的验证思路 前端:form表单 后台:创建form类,当请求到来时,先匹配,匹配出 ...
- winform - json串的转换
通过java接口,或者查询数据库返回json串. 可以有两种方式进行解读. 1.简单方式 没有深层结构,最好只有一条数据(当然也可多条).可以用datatable来获取.返回的是clo0.clo1.c ...
- PHP新手之学习类与对象(2)
二.自动加载对象 很多开发者写面向对象的应用程序时对每个类的定义建立一个 PHP 源文件.一个很大的烦恼是不得不在每个脚本(每个类一个文件)开头写一个长长的包含文件列表. 在 PHP 5 中,不再需要 ...
- 3.3. 轻量级的迁移方式(Core Data 应用程序实践指南)
持久化存储协调器会试着用新版的模板打开原来的持久化存储区,但是那是旧的模板,旧的格式,当然会出错.现在要做的就是迁移现有的持久化数据区,以便跟新模型匹配. 怎么进行迁移呢? 在什么时候进行迁移? 在向 ...
- 【HDU 5808】 Price List Strike Back (整体二分+动态规划)
Price List Strike Back There are nn shops numbered with successive integers from 11 to nn in Bytelan ...
- Coding 代码管理快速入门
当项目创建好了之后,我们该如何上传代码到 coding 上呢?Coding 网站使用“ Git 仓库”(类似 github )来管理代码.其操作原理在于:利用 git 服务,将本地的项目目录下的文件同 ...
- Webx3学习笔记(2)——基本流程
Webx3项目是运行在jetty/tomcat这种Web应用容器中的,Web应用的模式都是请求-响应的.一个请求通过浏览器发出,封装为HTTP报文到达服务端,被容器接受到,封装为HttpRequest ...
- 查找子字符串----KMP算法深入剖析
假设主串:a b a b c a b c a c b a b 子串:a b c a c 1.一般匹配算法 逐个字符的比较,匹配过程如下: 第一趟匹配 a b a b c a b c a c ...
- Cocos2d-x 多分辨率适配完全解析
从Cocos2d-x 2.0.4开始,Cocos2d-x提出了自己的多分辨率支持方案,废弃了之前的retina相关设置接口,提出了design resolution概念. 有以下相关接口: CCEGL ...