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!)
No comments:
Post a Comment