Вложенный элемент управления Accordion <Accordion <ListView ItemEditing Issue
У меня есть вопрос, и я совершенно сбит с толку, почему он не работает. У меня есть элемент управления ListView, вложенный в AJAX Accordion, который вложен в другой AJAX Accordion.
т.е. Accordion1 Все эти элементы управления привязаны к коду. В настоящее время я реализовал метод, который позволяет мне редактировать содержимое любого ListView, но это работает только на первой панели Accordion1. Каждая запись, если она находится на первой панели Accordion1, может быть отредактирована без каких-либо проблем. Когда я нажимаю кнопку "Редактировать" в ListView, когда он находится на любой другой панели Accordion1, он не изменяет ListView на EditItemTemplate. Я подумал, что это может быть проблема именования с уникальным идентификатором, назначенным для ListViews, но они разные (хотя и ненамного). ((System.Web.UI.Control) (lSender)). UniqueID "ctl00 $ MainContent $ ticketAccordion $ acc_ticketTypeAccordion_Pane_0_content $ acc_ticketAccord> ion_Pane_0_content $ LV_ticketDataListview" строка ((System.Web.UI.Control)(lSender)).UniqueID "ctl00$MainContent$ticketAccordion$acc_ticketTypeAccordion_Pane_1_content$acc_ticketAccord>ion_Pane_0_content$LV_ticketDataListview" строка Вот мой код для контроля: И вот мой код позади:<%@ 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 ответ
Нашел решение для моей проблемы. После долгих поисков я обнаружил, что проблема в том, что ClientID вложенных элементов управления идентичен.
Я использовал это как решение: Аккордеон: "ID xxx УЖЕ ОПРЕДЕЛЕН"