急!请教datalist嵌套 内层datalist编辑问题

zhuyuan0506 2009-05-17 11:25:50
外层:DataList1
内层:DataList2
内外层数据绑定正常
问题:现在想在内层进行编辑操作(即在内层 方法DataList2_EditCommand 里怎么写,关键要让内层datalist2进入编辑状态? )
内层删除可以,但内层编辑时,始终无法找到内层datalist2使其进入编辑状态?

以下是我写的内层“编辑”按钮事件
protected void DataList2_EditCommand(object source, DataListCommandEventArgs e)
{
DataList DataList2= (DataList)e.Item.FindControl("DataList2");
//(e.Item.Parent.FindControl("DataList2") as DataList).EditItemIndex = e.Item.ItemIndex;
DataList2.EditItemIndex = e.Item.ItemIndex;
BindData();
}
运行出错:提示DataList2为null

求高手帮帮忙,关键是如何让内层datalist2使其进入编辑状态,获取内层DataList2应该是关键(老是NULL)

我是新人 不能给分 请大家帮忙下~~ 急啊!
...全文
115 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zhuyuan0506 2009-05-17
前台的“编辑”我也是用linkButton按钮
关键是点击“编辑”后,想让该行 变成可编辑状态

看加粗的部分就可以了


在前台代码:

<asp:DataList ID="dlFirst" runat="server" RepeatColumns="1" Width="86%" OnItemDataBound="dlFirst_ItemDataBound" OnCancelCommand="dlFirst_CancelCommand" OnDeleteCommand="dlFirst_DeleteCommand" OnEditCommand="dlFirst_EditCommand" OnUpdateCommand="dlFirst_UpdateCommand">

<ItemTemplate>
<asp:Label ID="lblFirst" runat="server" Text=' <%# Eval("FID") %>' Visible="False"> </asp:Label>
<div class="dlm"><img src="../img/expand.gif"/> <asp:Label ID="lblTitle" runat="server" Text=' <%# Bind("FTitle") %>'></asp:Label>
</div>
<div class="dxg">
<asp:LinkButton ID="lnkbtnUpdateFirst" runat="server" CommandName="Edit" Text="编辑" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
<asp:LinkButton ID="lnkbtnDeleteFirst" runat="server" CommandName="Delete" Text="删除" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
</div>
<!------------二级分类开始-------------->
<asp:DataList ID="dlSecond" runat="server" OnCancelCommand="dlSecond_CancelCommand" OnDeleteCommand="dlSecond_DeleteCommand" OnEditCommand="dlSecond_EditCommand" OnUpdateCommand="dlSecond_UpdateCommand" >
<ItemTemplate>
<asp:Label ID="lblSecond" runat="server" Text=' <%# Eval("FID") %>' Visible="False"> </asp:Label>
<div class="zlm"><img src="../img/collapse.gif" border="0"/> <asp:Label ID="lblSecondTitle" runat="server" Text=' <%# Bind("FTitle") %>'></asp:Label>
</div>
<div class="zxg" >
<asp:LinkButton ID="lnkbtnUpdateSecond" runat="server" CommandName="Edit" Text="编辑" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
<asp:LinkButton ID="lnkbtnDeleteSecond" runat="server" CommandName="Delete" Text="删除" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
</div>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblSecond" runat="server" Text=' <%# Eval("FID") %>' Visible="False"> </asp:Label>
<div class="zlm"><img src="../img/collapse.gif" border="0"/> <asp:TextBox ID="txtSecondTitle" runat="server" Text=' <%# Bind("FTitle") %>'></asp:TextBox>
</div>
<div class="zxg" >
<asp:LinkButton ID="lnkbtnUpdateSecond" runat="server" CommandName="Update" Text="更新" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
<asp:LinkButton ID="lnkbtnCancelSecond" runat="server" CommandName="Cancel" Text="取消" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
<asp:LinkButton ID="lnkbtnDeleteSecond" runat="server" CommandName="Delete" Text="删除" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
</div>
</EditItemTemplate>
</asp:DataList>
</ItemTemplate>



<EditItemTemplate>
<asp:Label ID="lblFirst" runat="server" Text=' <%# Eval("FID") %>' Visible="False"> </asp:Label>
<div class="dlm"><img src="../img/expand.gif"/> <asp:TextBox ID="txtTitle" runat="server" Text=' <%# Bind("FTitle") %>'></asp:TextBox>
</div>
<div class="dxg">
<asp:LinkButton ID="lnkbtnUpdateFirst" runat="server" CommandName="Update" Text="更新" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
<asp:LinkButton ID="lnkbtnCancelFirst" runat="server" CommandName="Cancel" Text="取消" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
<asp:LinkButton ID="lnkbtnDeleteFirst" runat="server" CommandName="Delete" Text="删除" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
</div>
<!------------二级分类开始-------------->
<asp:DataList ID="dlSecond" runat="server" OnCancelCommand="dlSecond_CancelCommand" OnDeleteCommand="dlSecond_DeleteCommand" OnEditCommand="dlSecond_EditCommand" OnUpdateCommand="dlSecond_UpdateCommand" >
<ItemTemplate>
<asp:Label ID="lblSecond" runat="server" Text=' <%# Eval("FID") %>' Visible="False"> </asp:Label>
<div class="zlm"><img src="../img/collapse.gif" border="0"/> <asp:Label ID="lblSecondTitle" runat="server" Text=' <%# Bind("FTitle") %>'></asp:Label>
</div>
<div class="zxg" >
<asp:LinkButton ID="lnkbtnUpdateSecond" runat="server" CommandName="Edit" Text="编辑" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
<asp:LinkButton ID="lnkbtnDeleteSecond" runat="server" CommandName="Delete" Text="删除" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
</div>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblSecond" runat="server" Text=' <%# Eval("FID") %>' Visible="False"> </asp:Label>
<div class="zlm"><img src="../img/collapse.gif" border="0"/> <asp:TextBox ID="txtSecondTitle" runat="server" Text=' <%# Bind("FTitle") %>'></asp:TextBox>
</div>
<div class="zxg" >
<asp:LinkButton ID="lnkbtnUpdateSecond" runat="server" CommandName="Update" Text="更新" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
<asp:LinkButton ID="lnkbtnCancelSecond" runat="server" CommandName="Cancel" Text="取消" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
<asp:LinkButton ID="lnkbtnDeleteSecond" runat="server" CommandName="Delete" Text="删除" CommandArgument='<%# Eval("FID") %>'></asp:LinkButton>
</div>
</EditItemTemplate>
</asp:DataList>
</EditItemTemplate>
<ItemStyle VerticalAlign="Top" />
</asp:DataList>
回复
lzzz999 2009-05-17
你写编辑里就可以用linkButton按钮,然后在后台写个事件.
回复
lzzz999 2009-05-17

前台
<asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_Command">查看</asp:LinkButton>


后台

protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
Response.Write("<javascript>alert('hello!')</javascript>");
}

就这样
希望对你有帮助.
回复
相关推荐
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2009-05-17 11:25
社区公告
暂无公告