datagrid|解决我觉得我的例子和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;
我的DataGrid嵌套DataList(未解决)
80酷酷网 80kuku.com