嵌套控制手风琴<手风琴< ListView ItemEditing问题

时间:2013-08-20 14:20:14

标签: asp.net listview accordion edititemtemplate

有一个问题,我很困惑为什么它不起作用。我有一个嵌套在AJAX Accordion中的ListView控件,它嵌套在另一个AJAX Accordion中。

即。 Accordion1< Accordion2<的ListView

所有这些控件都在代码隐藏中进行数据绑定。

我目前实现了一种方法,允许我编辑任何ListView的内容,但这仅适用于Accordion1的第一个窗格。只要它在Accordion1的第一个窗格中,每条记录都可以编辑而没有任何问题。

当我在ListView中单击“编辑”按钮时,它位于Accordion1的任何其他窗格中时,它不会将ListView更改为EditItemTemplate。我认为这可能是分配给ListViews的UniqueID的命名问题,但它们是不同的(虽然不是很多)。

  

((System.Web.UI.Control)(lSender))。UniqueID“ctl00 $ MainContent $ ticketAccordion $ acc_ticketTypeAccordion_Pane_0_content $ acc_ticketAccord> ion_Pane_0_content $ LV_ticketDataListview”string

     

((System.Web.UI.Control)(lSender))。UniqueID“ctl00 $ MainContent $ ticketAccordion $ acc_ticketTypeAccordion_Pane_1_content $ acc_ticketAccord> ion_Pane_0_content $ LV_ticketDataListview”string

以下是我的控件代码:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TicketAccordion.ascx.cs" Inherits="GSWebApp.UserControls.TicketAccordion" %>

<ajaxToolkit:Accordion ID="acc_ticketTypeAccordion" runat="server" RequireOpenedPane="false" OnItemDataBound="acc_ticketTypeAccordion_ItemDataBound">
    <HeaderTemplate>
        <asp:Label ID="Lbl_statName" runat="server" Text='<%# Eval("StatName") %>'></asp:Label>
        <asp:HiddenField ID="Hdn_statID" runat="server" Value='<%# Eval("StatID") %>' />
        <asp:Label ID="Lbl_statCount" runat="server"></asp:Label>
    </HeaderTemplate>
    <ContentTemplate>

        <asp:HiddenField ID="Hdn_statID" runat="server" Value='<%# Eval("StatID") %>' />
        <ajaxToolkit:Accordion ID="acc_ticketAccordion" runat="server" RequireOpenedPane="false" OnItemDataBound="ticketAccordion_ItemDataBound">
            <HeaderTemplate>
                <table class="TicketAccordionTable">
                    <tr>
                        <td class="FLoatLeft">
                            <asp:Label ID="Lbl_ticketID" runat="server" Text='<%# "Ticket Ref# " + Eval("SupportTicketID") + " - " %>' CssClass="TLabel"></asp:Label>
                            <asp:Label ID="Lbl_ticketSumm" runat="server" Text='<%# Eval("SupportSummary") %>' CssClass="TLabel"></asp:Label>
                        </td>
                        <td class="FloatRight">
                            <asp:Label ID="Lbl_ticketDateLog" runat="server" Text='<%# Eval("DateLogged", "{0:dd/MM/yy HH:mm:ss}") %>' CssClass="TLabel"></asp:Label>
                        </td>
                    </tr>
                </table>
            </HeaderTemplate>
            <ContentTemplate>
                <asp:UpdatePanel ID="UpdPnl_ticketData2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
                    <ContentTemplate>
                        <asp:HiddenField ID="Hdn_supportTicketID" runat="server" Value='<%# Eval("SupportTicketID") %>' />
                        <asp:ListView ID="LV_ticketDataListview" runat="server" DataKeyNames="SupportTicketID" ItemPlaceholderID="itemPlaceholder"
                            OnItemEditing="LV_ticketDataListview_ItemEditing"
                            OnItemCanceling="LV_ticketDataListview_ItemCanceling"
                            OnItemInserting="LV_ticketDataListview_ItemInserting"
                            OnItemUpdating="LV_ticketDataListview_ItemUpdating"
                            OnItemDeleting="LV_ticketDataListview_ItemDeleting">
                            <LayoutTemplate>
                                <table class="TicketListViewTable">
                                    <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                                </table>
                                <footer>
                                    <asp:Button ID="Btn_editTicketData" runat="server" Text="New Reply" CssClass="TLVButton" OnClick="Btn_editTicketData_Click" />
                                    <asp:Button ID="Btn_deleteTicketData" runat="server" CommandName="Delete" Text="Delete Ticket" OnClientClick="if(!confirm('Are you sure you want to delete this ticket?')) return false;" CssClass="TLVButton" />
                                </footer>
                            </LayoutTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <asp:Label ID="Lbl_LV_ticketLog" runat="server" Text='<%# "Logged By: " + Eval("LoggedByEmployeeName") + " - " + Eval("TimeStamp") %>' CssClass="TLabelLog"></asp:Label></td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="Lbl_LV_ticketMessage" runat="server" Text='<%# Eval("MessageLog") %>' CssClass="TLabel"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Button ID="Btn_editTicketData" runat="server" CommandName="Edit" CommandArgument='<%# Eval("SupportTicketID") %>' Text="Edit" CssClass="TLVButton" />
                                        <asp:Button ID="Btn_deleteTicketData" runat="server" CommandName="Delete" Text="Delete" CssClass="TLVButton" />
                                    </td>
                                </tr>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:HiddenField ID="Hdn_supportTicketDataID" runat="server" Value='<%# Eval("SupportTicketDataID") %>' />
                                <tr>
                                    <td>
                                        <asp:Label ID="Lbl_LV_ticketLog" runat="server" Text='<%# "Logged By: " + Eval("LoggedByEmployeeName") + " - " + Eval("TimeStamp") %>' CssClass="TLabelLog"></asp:Label></td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:TextBox ID="Tb_LV_ticketMessage" runat="server" Text='<%# Eval("MessageLog") %>' CssClass="TLabel"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Button ID="Btn_saveTicketData" runat="server" CommandName="Update" Text="Save" CssClass="TLVButton" />
                                        <asp:Button ID="Btn_cancelTicketData" runat="server" CommandName="Cancel" Text="Cancel" CssClass="TLVButton" />
                                    </td>
                                </tr>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <tr>
                                    <td>
                                        <asp:TextBox ID="Tb_LV_ticketMessage" runat="server" CssClass="TLabel"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Button ID="Btn_saveTicketData" runat="server" CommandName="Insert" Text="Save" CssClass="TLVButton" />
                                        <asp:Button ID="Btn_cancelTicketData" runat="server" CommandName="Cancel" Text="Cancel" CssClass="TLVButton" />
                                    </td>
                                </tr>
                            </InsertItemTemplate>
                            <ItemSeparatorTemplate>
                            </ItemSeparatorTemplate>
                        </asp:ListView>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </ContentTemplate>
        </ajaxToolkit:Accordion>
    </ContentTemplate>
</ajaxToolkit:Accordion>

这是我的代码隐藏:

public partial class TicketAccordion : System.Web.UI.UserControl
    {
        GSWIISAService.GSWebServiceClient serviceClient;
        List<SupportTicket> ticketHoldList;
        List<SupportTicketData> ticketDataHoldList;

        protected void Page_Load(object sender, EventArgs e)
        {
            serviceClient = new GSWIISAService.GSWebServiceClient();
            BindLists(1006);
            BindAccTicketAccordion();
        }

        private void BindLists(int _clientRef)
        {
            ticketHoldList = serviceClient.GetSupportTicketsByReference(_clientRef).ToList();
            ticketDataHoldList = serviceClient.GetSupportTicketDataByRefID(_clientRef).ToList();
        }

        private void BindAccTicketAccordion()
        {
            acc_ticketTypeAccordion.DataSource = (from c in ticketHoldList select new { StatID = c.StatusID, StatName = c.Status }).Distinct().ToList();
            acc_ticketTypeAccordion.DataBind();
        }

        protected void ticketAccordion_ItemDataBound(object sender, AccordionItemEventArgs e)
        {
            if (e.ItemType == AccordionItemType.Content)
            {
                HiddenField hdnID = (HiddenField)e.AccordionItem.FindControl("Hdn_supportTicketID");
                int ID = int.Parse(hdnID.Value);
                ListView ticketListview = (ListView)e.AccordionItem.FindControl("LV_ticketDataListview");
                ticketListview.DataSource = ticketDataHoldList.Where(p => p.SupportTicketID == ID);
                ticketListview.DataBind();
            }
        }

        protected void acc_ticketTypeAccordion_ItemDataBound(object sender, AccordionItemEventArgs e)
        {
            if (e.ItemType == AccordionItemType.Header)
            {
                HiddenField hdnStatID = (HiddenField)e.AccordionItem.FindControl("Hdn_statID");
                int statID = int.Parse(hdnStatID.Value);
                Label statCount = (Label)e.AccordionItem.FindControl("Lbl_statCount");
                statCount.Text = " (" + ticketHoldList.Where(p => p.StatusID == statID).Count().ToString() + ")";
            }
            if (e.ItemType == AccordionItemType.Content)
            {
                HiddenField hdnStatID = (HiddenField)e.AccordionItem.FindControl("Hdn_statID");
                int statID = int.Parse(hdnStatID.Value);
                Accordion accTicketAccordion = (Accordion)e.AccordionItem.FindControl("acc_ticketAccordion");
                accTicketAccordion.DataSource = ticketHoldList.Where(p => p.StatusID == statID);
                accTicketAccordion.DataBind();             
            }
        }

        protected void LV_ticketDataListview_ItemEditing(object sender, ListViewEditEventArgs e)
        {        
            ListView lSender = (ListView)sender;
            lSender.EditIndex = e.NewEditIndex;
            HiddenField hdnSupportTicketID = (HiddenField)lSender.Parent.FindControl("Hdn_supportTicketID");
            lSender.DataSource = ticketDataHoldList.Where(p => p.SupportTicketID == int.Parse(hdnSupportTicketID.Value));
            lSender.DataBind();
        }

        protected void LV_ticketDataListview_ItemCanceling(object sender, ListViewCancelEventArgs e)
        {
            ListView lSender = (ListView)sender;
            lSender.EditIndex = -1;
            lSender.InsertItemPosition = InsertItemPosition.None;
            lSender.DataBind();
        }

        protected void LV_ticketDataListview_ItemInserting(object sender, ListViewInsertEventArgs e)
        {

        }

        protected void LV_ticketDataListview_ItemUpdating(object sender, ListViewUpdateEventArgs e)
        {
            ListView lSender = (ListView)sender;
            HiddenField hdnSupportTicketDataID = (HiddenField)lSender.Items[e.ItemIndex].FindControl("Hdn_supportTicketDataID");
            TextBox tbMessage = (TextBox)lSender.Items[e.ItemIndex].FindControl("Tb_LV_ticketMessage");

            SupportTicketDataEntity entity = new SupportTicketDataEntity();
            int stDataID = int.Parse(hdnSupportTicketDataID.Value);
            entity.SupportTicketDataID = stDataID;
            entity.MessageLog = tbMessage.Text;
            entity.Edited = true;
            //entity.EditedByID = Page.User.Identity.Name;
            entity.EditTimeStamp = DateTime.Now;

            serviceClient.UpdateSupportTicketData(entity);
            BindLists(1006);
            BindAccTicketAccordion();
            //lSender.DataBind();
        }

        protected void LV_ticketDataListview_ItemDeleting(object sender, ListViewDeleteEventArgs e)
        {

        }

        protected void Btn_editTicketData_Click(object sender, EventArgs e)
        {
            Button bSender = (Button)sender;
            ListView bSenderListview = (ListView)bSender.Parent.Parent;
            bSenderListview.InsertItemPosition = InsertItemPosition.LastItem;

            BindAccTicketAccordion();
        }

1 个答案:

答案 0 :(得分:0)

找到我的问题的修复程序。经过大量的谷歌搜索,我发现问题是嵌套控件的ClientID是相同的。

我用它作为解决方案:Accordion related: "ID xxx ALREADY DEFINED"