Showing posts with label pane. Show all posts
Showing posts with label pane. Show all posts

Monday, March 26, 2012

How do I Databind to a GridView inside an Accordion Pane

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="http://links.10026.com/?link=" 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

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

<atlasToolkit:AccordionID="MyAccordion"runat="server"SelectedIndex="0"

HeaderCssClass="accordionHeader"ContentCssClass="accordionContent"

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

</atlasToolkit:Accordion>

code behind:

...

AccordianPane pane =newAccordionPane();

pane.HeaderContainer.Controls.Add(newLiteralControl("headerName"));

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

MyAccordion.Controls.Add(pane);

privateGridView GetGridView(){

GridView gridView =newGridView();

...

}


Thanks for the help that worked Perfect.

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*/ }

I found the solution

grid.SelectedIndexChanged += new EventHandler(grid_SelecetedIndexChanged);

void grid_SelectedIndexChanged(Object sender, EventsArgs e)
{

}


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.


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 athttp://couldbedone.blogspot.com/2007/07/what-wrong-with-accordion-control.html (thanks to Yuriy!)

Saturday, March 24, 2012

How can retrieve data dynamically into the <content> tag of Accordion pane when clic

How can retrieve data dynamically into the <content> tag of <Accordion pane> when clicking a button which is in the <Header> tag of< Accordion pance>

Plase let me know if any possibility

Thanks,

Eswar

Hi,

I'm not sure if I understood you correctly. please try the sample below or feel free to let me know if I misunderstood you:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { } void btnCommand(object sender, CommandEventArgs e) { int index = int.Parse(e.CommandArgument.ToString()); AjaxControlToolkit.AccordionPane ap = accordion1.Panes[index]; TextBox tb = ap.ContentContainer.FindControl("TextBox" + (index+1).ToString()) as TextBox; tb.Text = DateTime.Now.ToString(); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Untitled Page</title></head><body><form id="form1" runat="server"><asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager><div> <input id="Button1" type="button" value="button" onclick="addTab();"/> <ajaxToolkit:Accordion runat="server" ID="accordion1"> <Panes> <ajaxToolkit:AccordionPane runat="server"> <Header> <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument="0" OnCommand="btnCommand">LinkButton1</asp:LinkButton> </Header> <Content> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </Content> </ajaxToolkit:AccordionPane> <ajaxToolkit:AccordionPane ID="AccordionPane1" runat="server"> <Header> <asp:LinkButton ID="LinkButton2" runat="server" CommandArgument="1" OnCommand="btnCommand">LinkButton2</asp:LinkButton> </Header> <Content> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </Content> </ajaxToolkit:AccordionPane> <ajaxToolkit:AccordionPane ID="AccordionPane2" runat="server"> <Header> <asp:LinkButton ID="LinkButton3" runat="server" CommandArgument="2" OnCommand="btnCommand">LinkButton3</asp:LinkButton> </Header> <Content> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </Content> </ajaxToolkit:AccordionPane> </Panes> </ajaxToolkit:Accordion> </div></form></body></html>