How do I Databind to a GridView inside an Accordion Pane

Last post 11-07-2007 6:58 AM by brentj. 6 replies.

Sort Posts:

  • How do I Databind to a GridView inside an Accordion Pane

    10-06-2006, 5:18 PM
    • Loading...
    • Bizzy
    • Joined on 10-06-2006, 4:30 PM
    • Posts 6

    I am trying to DataBind the results of a query to a GridView Control inside an Accoridon Pane.  I can get the data from the elements in the Accordion Pane but I don't know how to add or bind data to them.  Here is my code

    ASP Code 

    <atlasToolkit:Accordion ID="MyAccordion" runat="server" SelectedIndex="0"
                                    HeaderCssClass="accordionHeader" ContentCssClass="accordionContent"
                                    FadeTransitions="true" FramesPerSecond="40" TransitionDuration="250"
                                    AutoSize="none" >
                <atlasToolkit:AccordionPane ID="AccordionRest" runat="server" >
                <Header>
                <a href="" onclick="return false;" class="accordionLink">Restricted Items</a>
                </Header>
                <Content><h1>Restrict SKUs</h1>
                    <asp:Label ID="lRestricted" runat="server" Text="This Months Restricted SKUS"></asp:Label>
                    <asp:GridView ID="gvRestricted" runat="server"></asp:GridView>   <!-- This is the GridView I want to DataBind my DataSet to  -->
                    <asp:Button ID="bRestricted" runat="server" OnClick="bRest_Click1" Text="Button" />
                </Content>
        </atlasToolkit:AccordionPane>

    < /atlasToolkit:Accordion>

     

     

    C# code 

    protected void Page_Load(object sender, EventArgs e)
        {
            String invoice = Session["invoice"].ToString();
            DataSet data = ws.fillMain(invoice);  //webservice to returns a DataSet
            GridView gvRest = (GridView)AccordionRest.ContentContainer.FindControl("gvRest");  //This how I would get GridView, but I doesn't work to add  Data to a GridView
            gvRest.DataSource = data.Tables[0];
            gvRest.DataBind();
        }

     

    If anyone has run into this problem and has figured out how to do this please let me know, thank you 

     

     

    Filed under: ,
  • Re: How do I Databind to a GridView inside an Accordion Pane

    10-07-2006, 7:25 PM
    • Loading...
    • champ1979
    • Joined on 06-17-2006, 5:59 PM
    • Posts 64

    I would create and bind the gridview in codebehind....

    <atlasToolkit:Accordion ID="MyAccordion" runat="server" SelectedIndex="0"

    HeaderCssClass="accordionHeader" ContentCssClass="accordionContent"

    FadeTransitions="true" FramesPerSecond="40" TransitionDuration="250" AutoSize="None">

    </atlasToolkit:Accordion>

    code behind:

     ....

    AccordianPane pane = new AccordionPane();

    pane.HeaderContainer.Controls.Add(new LiteralControl("headerName"));

    pane.ContentContainer.Controls.Add(GetGridView());

    MyAccordion.Controls.Add(pane);

    private GridView GetGridView(){

     

    GridView gridView = new GridView();

    ...

    }

     

  • Re: How do I Databind to a GridView inside an Accordion Pane

    10-09-2006, 9:46 AM
    • Loading...
    • Bizzy
    • Joined on 10-06-2006, 4:30 PM
    • Posts 6
    Thanks for the help that worked Perfect.
  • Re: How do I Databind to a GridView inside an Accordion Pane

    10-09-2006, 11:55 AM
    • Loading...
    • Bizzy
    • Joined on 10-06-2006, 4:30 PM
    • Posts 6

    I was able to add and populate the GridView control on the Accordion Pane.  But I ran into an new obsticle.  I have added a CommandField column to my GridView, and I want to catch the event when my commandview is selected.  But I don't know how to declare the OnSelectedIndexChange in the code behind, and i dont' know if I catching the event correctly. Any help would be greatly appreciated, I am fairly new to ASP and Atlas, so detailed explainations and code examples are greatley appreicated. 
     

    Here is my code.

     

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                String invoice = Session["invoice"].ToString();
                DataSet data = ws.fillCustomer(invoice);
                GridView gvRestricted = NewGridView();
    
       /*how do I add a Command Field Event so I can catch it*/
                gvRestricted.DataSource = data.Tables[0];
                gvRestricted.DataBind();
                AccordionRest.ContentContainer.Controls.Add(gvRestricted);
            }
            catch
            {
            }
        }
    
        public GridView NewGridView()
        {
            CommandField delete = new CommandField();
            delete.ShowDeleteButton = true;
            delete.DeleteText = "Clear";
    
            GridView grid = new GridView();
            grid.CssClass = "gridView";
            grid.HeaderStyle.CssClass = "gridViewHeader";
            grid.FooterStyle.CssClass = "gridViewFooter";
            grid.AlternatingRowStyle.CssClass = "gridViewAlternate";
            grid.PagerStyle.CssClass = "gridViewPager";
            grid.RowStyle.CssClass = "gridViewRow";
            grid.Columns.Add(delete);
            return grid;
        }
    
    
        void gvRest_DeleteIndexChanged(Object sender, EventArgs e)
        {
            GridView grid = (GridView)AccordionRest.ContentContainer.FindControl("gvRest");
            GridViewRow row = grid.SelectedRow;
    
              /*This is where I need to hand the event of the command field being triggered*/
        }
     
  • Re: How do I Databind to a GridView inside an Accordion Pane

    10-12-2006, 9:34 AM
    • Loading...
    • Bizzy
    • Joined on 10-06-2006, 4:30 PM
    • Posts 6

    I found the solution

     

    grid.SelectedIndexChanged += new EventHandler(grid_SelecetedIndexChanged);

     

    void grid_SelectedIndexChanged(Object sender, EventsArgs e)
    {

  • Re: How do I Databind to a GridView inside an Accordion Pane

    10-22-2007, 8:05 PM

    I created the grid in code behind and register the PAgeIndexChanging event, but when I click in a diferent Page number the event hadlr is not fired or is filtreded by the accordion control and I don't get to change the page. Besides the site does a Posta back, whichi is not correct, because the accordion is inside a UpdataPanel de Ajax.

     

    I don't know how to solve this issue.

     

    Thank in advance for you help.

  • Re: How do I Databind to a GridView inside an Accordion Pane

    11-07-2007, 6:58 AM
    • Loading...
    • brentj
    • Joined on 08-16-2006, 11:26 AM
    • Posts 3

    Try doing this for each AccordionControl on your page in the Page_Load event (before doing anything else with the AccordionControls):

     
    Accordion1.FindControl("dummy");
      

    The "dummy" name isn't important, it's just that calling the FindControl method works around the problem. The full details of the problem were posted at http://couldbedone.blogspot.com/2007/07/what-wrong-with-accordion-control.html (thanks to Yuriy!)

Page 1 of 1 (7 items)
Microsoft Communities
Page view counter