Hi sillysoumare,
I have built a test application based on your situation, and all the event which is inside the AccordionPane’s Content area could be fired normally. I built the page by following the method which I provided above:
- Create the LinkButton and its Click event outside the Template, then move it into the Template tag.
- Create the DataGrid and its SelectedIndexChanged event outside, then move it into the AccordionPane’s Content tag.
- In the DataGrid, I add two Columns- the Select Command Column & the Template Column to test the events separately.
Please refer to my code here:
.aspx file
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestDataGridInAccordion.aspx.cs"
Inherits="SoluTest_CSApplication.TestDataGridInAccordion" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<link href="Stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<cc1:Accordion ID="Accordion1" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelect" ContentCssClass="accordionContent"
FadeTransitions="True" FramesPerSecond="40" TransitionDuration="250" AutoSize="None"
RequireOpenedPane="false" SuppressHeaderPostbacks="true">
<Panes>
<cc1:AccordionPane ID="AccordionPane1" runat="server">
<Header>
<p>
This is the header area! Please click a link.</p>
</Header>
<Content>
<asp:DataGrid ID="DataGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
CellPadding="0" OnSelectedIndexChanged="DataGrid1_SelectedIndexChanged">
<Columns>
<asp:ButtonColumn HeaderText="Command" CommandName="Select" Text="Select" DataTextField="Field1">
</asp:ButtonColumn>
<asp:TemplateColumn HeaderText="Template">
<ItemTemplate>
<ul style="list-style-type: square">
<li>
<asp:LinkButton ID="lbtnReport" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Field1") %>'
CausesValidation="False" OnClick="lbtnReport_Click"></asp:LinkButton>
</li>
</ul>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</Content>
</cc1:AccordionPane>
</Panes>
</cc1:Accordion>
The result:
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"
ProviderName="<%$ ConnectionStrings:DatabaseConnectionString.ProviderName %>"
SelectCommand="SELECT [ID], [Field1] FROM [AssName]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
.aspx.cs file
public partial class TestDataGridInAccordion : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DataGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedChanged(sender, e);
}
protected void lbtnReport_Click(object sender, EventArgs e)
{
SelectedChanged(sender, e);
}
private void SelectedChanged(object sender, EventArgs e)
{
LinkButton lnkBtn = new LinkButton();
if (sender is DataGrid)
{
lnkBtn = (LinkButton)DataGrid1.SelectedItem.FindControl("lbtnReport");
}
else if (sender is LinkButton)
{
lnkBtn = (LinkButton)sender;
}
Label1.Text = "You have selected " + lnkBtn.Text;
}
}
You may modify it with yours and tell me the result.
Best regards,
Zhi-Qiang Ni