asp.net – 访问listview的edititemtemplate中的控件
发布时间:2020-12-16 07:33:32 所属栏目:asp.Net 来源:网络整理
导读:我正在使用listview控件.默认情况下,我使用编辑按钮显示itemtemplate.按下编辑按钮后,列表视图将切换到edititemtemplate.我需要根据正在编辑的项目填充edititemtemplate中的一个控件 – 我尝试在ItemEditing事件中访问控件(通过FindControl)(以及几乎所有其
我正在使用listview控件.默认情况下,我使用编辑按钮显示itemtemplate.按下编辑按钮后,列表视图将切换到edititemtemplate.我需要根据正在编辑的项目填充edititemtemplate中的一个控件 – 我尝试在ItemEditing事件中访问控件(通过FindControl)(以及几乎所有其他事件),但是控件只是’似乎存在.我可以在itemtemplate ok中访问控件,但不能访问edititemtemplate.
任何人都可以告诉我如何访问listview的edititemtemplate中的控件,以及我应该从哪个事件中执行此操作? 编辑 protected void UnitsLV_ItemEditing(object sender,ListViewEditEventArgs e) { ListViewItem item = UnitsLV.Items[e.NewEditIndex]; ListBox tempLB = (ListBox)e.item.FindControl("ListBox3"); } 我也尝试过ItemDataBound和ItemCreated. listview声明是: <asp:Content ID="Content1" ContentPlaceHolderID="ColumnA" runat="server"> <asp:Panel ID="Panel1" runat="server"> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Panel ID="SummaryPnl" runat="server"> <asp:ListView ID="UnitsLV" runat="server" DataSourceID="DataLDS" DataKeyNames="u_uid" InsertItemPosition="LastItem" OnItemInserting="UnitsLV_ItemInserting" OnItemDataBound="UnitsLV_ItemDataBound" OnItemCreated="UnitsLV_ItemCreated" onitemediting="UnitsLV_ItemEditing"> <ItemTemplate> <tr class="rowA"> <td> <asp:Label runat="server" ID="UnitIDLbl" Text='<%# Eval("u_uid")%>'></asp:Label> </td> <td> <%# Eval("u_Title")%> </td> <td> <asp:LinkButton ID="EditBtn" runat="server" CommandName="Edit" CommandArgument='<%#Eval("u_uid") %>' Text="Edit" /> </td> <td> <asp:LinkButton ID="DeleteBtn" runat="server" CommandName="Delete" CommandArgument='<%#Eval("u_uid") %>' Text="Delete" /> </td> </tr> </ItemTemplate> <InsertItemTemplate> <tr class="rowB"> <td> <br /> </td> <td> <br /> <asp:TextBox ID="TitleTB" runat="server" Text='<% #Bind("u_Title")%>'></asp:TextBox> </td> <td> <br /> <asp:ListBox ID="ListBox3" runat="server"></asp:ListBox> <asp:ListBox ID="ToBeDeletedLB" runat="server"></asp:ListBox> </td> <td> <asp:LinkButton ID="InsertBtn" runat="server" CommandName="Insert" Text="Insert" /> </td> <td> <asp:LinkButton ID="CancelBtn" runat="server" CommandName="Cancel" Text="Cancel" /> </td> </tr> </InsertItemTemplate> <EditItemTemplate> <tr class="rowB"> <td> <br /> <asp:Label runat="server" ID="UnitIDLbl" Text='<%# Bind("u_uid")%>'></asp:Label> </td> <td> <br /> <asp:TextBox ID="TitleTB" runat="server" Text='<% #Bind("u_Title")%>'></asp:TextBox> </td> <td> <br /> <asp:ListBox ID="ListBox3" runat="server"></asp:ListBox> <asp:ListBox ID="ToBeDeletedLB" runat="server"></asp:ListBox> </td> <td> <asp:LinkButton ID="UpdateBtn" runat="server" CommandName="Update" Text="Update" /> </td> <td> <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" Text="Cancel" /> </td> </tr> </EditItemTemplate> <LayoutTemplate> <table id="Table2" runat="server" width="100%"> <tr id="Tr1" runat="server"> <td id="Td1" runat="server"> <table id="itemPlaceholderContainer" runat="server" border="0" style="" width="100%"> <tr id="itemPlaceholder" runat="server"></tr> </table> </td> </tr> <tr id="Tr2" runat="server"> <td id="Td2" runat="server" style=""></td> </tr> </table> </LayoutTemplate> </asp:ListView> </asp:Panel> </ContentTemplate> </asp:UpdatePanel> </asp:Panel> </asp:Content> 编辑: foreach (Control child in control.Controls) { Control result = Find(child,id); if (result != null) { return result; } } **编辑:** 解决方法
我已经找到了一种方法来做我需要做的事情,尽管我对此并不十分满意.
protected void UnitsLV_ItemDataBound(object sender,ListViewItemEventArgs e) { if (UnitsLV.EditIndex > -1) { // Controls within the edititemtemplate are available via e.Item.FindControl("controlname") } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.Net/C#将NameValueCollection转换为IDictionary?
- asp.net-mvc – 如何在ASP.NET MVC RC1中返回304状态与File
- asp.net – ScriptManager.axd不会缓存
- asp.net – User.GetUserId()在控制器的构造函数内失败
- asp.net-mvc – ASP.NET MVC AjaxForm没有正确更新部分视图
- asp.net-mvc – ASP.NET MVC应用程序自定义错误页面不显示在
- asp.net-mvc – 在ASP.NET MVC中创建模型
- asp.net – BC30560:’default_aspx’在命名空间’ASP’中
- ASP.Net核心 – 获取帖子表格的所有数据
- ASP.NET MVC使用Oauth2.0实现身份验证
推荐文章
站长推荐
热点阅读