Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Friends

I am trying to bind accordion control at run time. Header is loading,but the content is not loading. please correct me where i gone wrong

This is the code to load accordion Header
C#
public DataTable EventName()
    {
        string tablename = "Event";
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "Select EventName from EventNames order by EventName";
        return GetData(cmd, tablename).Tables[0];
    }


In the page load event i write like this

C#
if (!IsPostBack)
    {
        dataacess da = new dataacess();

        DataTable dt = da.EventName();
        Accordion1.DataSource = dt.DefaultView;
        Accordion1.DataBind();

    }


the aspx page design is like this

ASP.NET
<asp:Accordion runat="server" ID="Accordion1" SuppressHeaderPostbacks="true" HeaderCssClass="accordionHeader"
        HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" Width="500"
        OnItemDataBound="Accordion1_ItemDataBound">
        <HeaderTemplate>
            <asp:Label runat="server" ID="lblEventName" Text='<%#Eval("EventName") %>'> </asp:Label>
        </HeaderTemplate>
        <ContentTemplate>
            <asp:HiddenField runat="server" ID="hidEventName" Value='<%#Eval("EventName") %>'>
            </asp:HiddenField>
           
                <asp:Repeater ID="Repeater1" runat="server">
                    <ItemTemplate>
                        <p>
                            <asp:Label runat="server" ID="litDate" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>'
                                Font-Size="Medium" ForeColor="Maroon" Font-Bold="True"></asp:Label><br />
                            
                                <asp:Literal runat="server" ID="litDesc1" Text='<%# "Date: " + DataBinder.Eval(Container.DataItem, "EDate", "{0:dd/MMM/yyyy,dddd}") %>'></asp:Literal>
                            
                            <br />
                            Description:
                            <asp:Literal runat="server" ID="litDesc2" Text='<%# DataBinder.Eval(Container.DataItem, "Description2") %>'></asp:Literal></p>
                    </ItemTemplate>
                    <SeparatorTemplate>
                        <hr />
                    </SeparatorTemplate>
                </asp:Repeater>
           
        </ContentTemplate>
    </asp:Accordion>


Accordion OnItemDataBound event
C#
protected void Accordion1_ItemDataBound(object sender, AjaxControlToolkit.AccordionItemEventArgs e)
   {
       if (e.ItemType==AjaxControlToolkit.AccordionItemType.Content)
       {
           Repeater Repeater1 = (Repeater)e.AccordionItem.FindControl("Repeater1");
           HiddenField hidEventName = (HiddenField)e.AccordionItem.FindControl("hidEventName");

           dataacess da = new dataacess();
           Repeater1.DataSource = da.EventHistory(pname, hidEventName.ToString());
           Repeater1.DataBind();
       }
   }


If i use the code separately to bind the repeater its working without any problem.
Where i should i make changes to work it proper
Posted
Comments
Inside Accordion1_ItemDataBound, have you checked if the below line executes or not.

Repeater Repeater1 = (Repeater)e.AccordionItem.FindControl("Repeater1");

1 solution

I find my mistake while debugging and found the sollution.
i changed .ToString() to .Value
C#
Repeater1.DataSource = da.EventHistory(pname, hidEventName.ToString());
C#
Repeater1.DataSource = da.EventHistory(pname, hidEventName.Value);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900