Hello everybody, i'm beginner. I have a problem:

I have this code:

<cc1:Accordion ID="Accordion2" runat="server" SelectedIndex="0" FadeTransitions="true"
FramesPerSecond="40" TransitionDuration="250" AutoSize="None" D[B]ataSourceID="SqlDataSource1"[/B] ContentCssClass="Content" HeaderCssClass="HEADER">
...
...
</cc1:Accordion>

The code inside of Accordion is executed for each row of SqlDataSource1.

I'd like if it is possible get actually row of SqlDataSource1 that it's reading , It's possible?.

Kind Regards.

Dani AI

Generated

Short answer: bind the child query to a value from the current outer row instead of trying to use the accordion selection. is creating one pane per row, so each pane needs its own parameter value. Two reliable patterns:

  1. Declarative, no code-behind
    Place a server control in the pane that is data-bound to the outer row (for example a HiddenField or Label using <%# Eval("Key") %>), then use a ControlParameter on the inner SqlDataSource to read that control. This keeps everything declarative and works when the inner SqlDataSource sits inside the same item template.

Example snippet:

<!-- inside the accordion item template -->
<asp:HiddenField ID="hfParentId" runat="server" Value='<%# Eval("ParentId") %>' />

<asp:SqlDataSource ID="sdsChild" runat="server"
    SelectCommand="SELECT ... WHERE ParentID = @ParentID">
  <SelectParameters>
    <asp:ControlParameter Name="ParentID" ControlID="hfParentId" PropertyName="Value" Type="Int32" />
  </SelectParameters>
</asp:SqlDataSource>
  1. Server-side per-item binding (more control)
    Handle the accordion item data event and, for each item, read the DataItem to get the key, find the nested SqlDataSource, set its SelectParameters value and then DataBind the child control. This guarantees the parameter comes directly from the current row.

Example pattern:

protected void Accordion1_ItemDataBound(object sender, AjaxControlToolkit.AccordionItemEventArgs e)
{
  var drv = e.Item.DataItem as DataRowView;
  if (drv == null) return;
  string key = drv["ParentId"].ToString();

  var sdsChild = e.Item.FindControl("sdsChild") as SqlDataSource;
  if (sdsChild != null)
  {
    sdsChild.SelectParameters["ParentID"].DefaultValue = key;
    var rpt = e.Item.FindControl("Repeater1") as Repeater;
    if (rpt != null) rpt.DataBind();
  }
}

Notes and troubleshooting

  • 's SelectedIndex is about which pane is active after rendering; it does not supply the current per-row DataItem while the template is being created.
  • Watch performance: one inner SqlDataSource per pane can produce N+1 queries. For many rows consider a single join or a pre-fetched child dataset grouped in memory.
  • If parameters are empty, verify naming-container scope (use FindControl to confirm the HiddenField exists in that item) and ensure binding expressions use <%# Eval %> so values are set during data binding.

Recommended Answers

All 5 Replies

>I'd like if it is possible get actually row of SqlDataSource1 that it's reading , It's possible?.

What do you want say? Please, come again.

Thanks for answer.
Well, for each row of SqlDataSource1 it put a accordion, and i need a new selectcommand inside of Accordion with a parameter what is a field of actual row of SqlDataSource1.

I think that when you link a control (like accordion) by DataSourceID="SqlDataSource1" it'll have some way to know the row that it reading in everytime.

Do you understand?.
Thanks very much.

I think that when you link a control (like accordion) by DataSourceID="SqlDataSource1" it'll have some way to know the row that it reading in everytime.

Hi,

To know the row that have been selected in accordion you need to use:

accordionName.SelectedIndex

Hi,

To know the row that have been selected in accordion you need to use:

accordionName.SelectedIndex

Thanks but that is not problem.

When you link the accordion by "datasourceid" , internally, it read all rows and for each row it paint a accordionpane, so, i need catch a field of the row that it is reading in that time because i have to do other sqldatasource inside of accordionpane using like parameter the value of a field of principal sqldatasource.

Thanks very much for answer.

Yea but after you have the selected index the sky is the limit :-),
what i mean you can use the accordion.Rows[SelectedIndex].Field or somthing like that, i'm not sure about the syntax but you can google it!

EDIT: I'm not sure about the syntax because i have never used accordion but all .Net controls are working almost the same way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.