我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > ASP专区 > Asp基础/应用 > 我的DataGrid嵌套DataList(未解决)
热门文章排行
热门文章排行 手推车”功能的实现(10-07)
八大法则防范ASP网站漏洞(10-23)
在JSP中访问数据库大全(10-23)
ASP教程十一、调试ASP脚本(10-23)
虚机服务中常见Asp.Net低级错误一览(03-21)
精采文章排行
精采文章排行 ASP.NET实现抓取网页中的链接(11-15)
ASP连接数据库的11种方法(11-10)
如何动态创建网页的RSS内容摘要(11-10)
ASP网站漏洞及入侵防范方法(11-10)
ASP自定义函数:对字符串正则替换(11-10)
技术专题推荐
网管论坛交流
 

我的DataGrid嵌套DataList(未解决) 

作者:佚名   来源:本站教程   点击:   日期:2007-03-22

我觉得我的例子和MSDN (saucer(思归)版)的大概是一致的,个人觉得问题出在为什么我的页面的dlReplyList在绑定前(就是击编辑按钮后)会是“未定义的值”的?如下图(上半):而saucer(思归)版的例子,在同一个断点,DataList实例ItemsList却是存在的(下半)


页面框架:

<asp:DataGrid Width="80%"
DataKeyField="PostId" ID="dgPostList" runat="server"
AllowPaging="True" PageSize="10" AutoGenerateColumns="false"
OnPageIndexChanged="TrunPage" OnEditCommand="EditPost"
OnDeleteCommand=DeletePost OnUpdateCommand=UpdatePost OnCancelCommand=CancelPost>
<pagerstyle Mode="NumericPages" Position="TopAndBottom" HorizontalAlign="Center"></pagerstyle>

<columns>
<asp:TemplateColumn>
<itemtemplate>
<table id="tbPostRecord" bgcolor="#dfdfdf" width="100%">
...
<div align="right">
<asp:ImageButton runat="server" ID="imgbtEdit" CommandName="edit" ImageUrl="images/edit.gif" AlternateText="编辑"></asp:ImageButton>
<asp:ImageButton runat="server" ID="imgbtDelete" CommandName="delete" ImageUrl="images/del.gif" AlternateText="删除"></asp:ImageButton>
......

<asp:DataList ID="dlReplyList" Width="100%" RepeatColumns=1
DataKeyField="PostId" RepeatDirection=Vertical runat="server"
OnEditCommand="EditReply" OnDeleteCommand=DeleteReply
OnUpdateCommand=UpdateReply OnCancelCommand=CancelReply
DataSource='<%# GetReplyData((int)DataBinder.Eval(Container.DataItem, "PostID"))%>'>

<itemtemplate>
<table id="tbReplyRecord" width="100%">
.....

<asp:ImageButton runat="server" ID="imgbtEdit2" CommandName="edit" ImageUrl="images/edit.gif" AlternateText="编辑"></asp:ImageButton>
<asp:ImageButton runat="server" ID="imgbtDelete2" CommandName="delete" ImageUrl="images/del.gif"
AlternateText="删除"></asp:ImageButton>
.......

</table>
</itemtemplate>
<EditItemTemplate>

<table id="tbReplyRecordEdit" width="100%">
..........
<asp:ImageButton runat="server" ID="imgbtSave" CommandName="update" ImageUrl="images/save.jpg" AlternateText="保存"></asp:ImageButton>
<asp:ImageButton runat="server" ID="imgbtCancel" CommandName="cancel" ImageUrl="images/cancel.jpg" AlternateText="取消"></asp:ImageButton>
...

</table>
</EditItemTemplate>
</asp:DataList>


</itemtemplate>
<EditItemTemplate>
<table id="tbPostRecordedit" bgcolor="#dfdfdf" width="100%">
.......
<asp:ImageButton runat="server" ID="imgbtSavePost" CommandName="update" ImageUrl="images/save.jpg"
AlternateText="保存"></asp:ImageButton>
<asp:ImageButton runat="server" ID="imgbtCancelPost" CommandName="cancel" ImageUrl="images/cancel.jpg" AlternateText="取消"></asp:ImageButton>
.........
</table>
</EditItemTemplate>
</asp:TemplateColumn>


</columns>
</asp:DataGrid>





后台代码,看有色部分

using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using fiveXdotNet.BLL;

namespace fiveXdotNet.Web
{
/// <summary>
/// index 的摘要说明。
/// </summary>
public class index : ScrollPage
{
protected System.Web.UI.WebControls.Label lblName;
protected System.Web.UI.WebControls.Label lblPostId;
protected System.Web.UI.WebControls.Label lblPostTime;
protected System.Web.UI.WebControls.Label lblContent;
protected System.Web.UI.WebControls.Label lblPosterName;
protected System.Web.UI.WebControls.Label lblReplyTime;
protected System.Web.UI.WebControls.Label lblReplyContent;
protected System.Web.UI.WebControls.DataGrid dgPostList;
protected System.Web.UI.WebControls.DataList dlReplyList;
protected System.Web.UI.HtmlControls.HtmlTextArea txaNewPost;
protected DataSet _ds = new DataSet();

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack){
bind();
}
//string s = this.Request.Form["txaNewPost"];
//string s01 = this.Request.Form["txt01"];
//string s02 = this.Request.Form["txaNewPost"];
}

private void bind(){
Post.getAllPost(ref _ds);
DataView dvPostList = new DataView(_ds.Tables[0], "PostType = 0","PostID desc",DataViewRowState.CurrentRows);
dgPostList.DataSource = dvPostList;
dgPostList.DataBind();
}
protected DataView GetReplyData(int iPostId){
DataView dvPostList = new DataView(_ds.Tables[0],"PostType = " + iPostId.ToString(),"PostID",DataViewRowState.CurrentRows);
//DataView dvPostList = new DataView(_ds.Tables[0]);
//dvPostList.RowFilter = "PostType = " + iPostId.ToString();
return dvPostList;
}

protected void TrunPage(object sender, DataGridPageChangedEventArgs e){
dgPostList.CurrentPageIndex = e.NewPageIndex;
dgPostList.EditItemIndex = -1;
this.bind();
}
protected void EditReply(object sender, System.Web.UI.WebControls.DataListCommandEventArgs e){
DataList dlReplyList = (DataList)sender;
dlReplyList.EditItemIndex = e.Item.ItemIndex;
dgPostList.EditItemIndex = -1;
DataGridItem dgi = (DataGridItem)dlReplyList.Parent.Parent;
int n = dgi.ItemIndex;
int nPostID = (int)dgPostList.DataKeys[n];
Post.getAllPost(ref _ds);
dlReplyList.DataSource = GetReplyData(nPostID);
dlReplyList.DataBind();
//dl.DataBind();
//dlReplyList.EditItemIndex = e.Item.ItemIndex;
//this.dlReplyList = dl;
//Post.getAllPost(ref _ds);
//this.dlReplyList.DataSource = GetReplyData(22);
//this.dlReplyList.DataBind();
//this.bind();
}
protected void EditPost(object sender, System.Web.UI.WebControls.DataGridCommandEventArgs e){
dgPostList.EditItemIndex = e.Item.ItemIndex;
this.bind();
}
protected void AddPost(object sender, System.Web.UI.ImageClickEventArgs e){
//string sContent = th

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·ASP中巧用Response属性 ·第六课:ASP脚本循环语句
·在 Web 页上使用条件数值格式 ·连接数据库查询手册(不仅仅适用于asp)
·警惕"给你的FileSystemObject对象加把锁" ·用ASP做全文检索

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。