有一个问题,我很困惑为什么它不起作用。我有一个嵌套在 AJAX Accordion 中的 ListView 控件,该控件嵌套在另一个 AJAX Accordion 中。
即 Accordion1 < Accordion2 < ListView
所有这些控件都在代码隐藏中进行数据绑定。
我目前实现了一种方法,允许我编辑任何 ListView 的内容,但这仅适用于 Accordion1 的第一个窗格。每条记录,只要它在 Accordion1 的第一个窗格中,都可以毫无问题地进行编辑。
当我在 Accordion1 的任何其他窗格中单击 ListView 中的 Edit 按钮时,它不会将 ListView 更改为 EditItemTemplate。我认为这可能是分配给 ListView 的 UniqueID 的命名问题,但它们是不同的(尽管差别不大)。
((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();
}