Click here to Skip to main content
13,259,194 members (50,923 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I am currently facing a situation where i have to send value to some page through query string.
The problem is that the link button is inside grid-view which is inside accordion pane.

All the panes are created dynamically and grid-view is filled in accordance with the values in pane.

<asp:Accordion ID="Accordion1" runat="server"
        TransitionDuration="300" FadeTransitions="true"
            ContentCssClass="accordion-content" HeaderCssClass="accordion-header"
            onitemdatabound="Accordion1_ItemDataBound" Width="100%"
               <asp:Label runat="server" ID="lblCategory" Text='<%# Eval("CName") %>'></asp:Label>
               <asp:HiddenField runat="server" ID="txtCategoryID" Value='<%#DataBinder.Eval(Container.DataItem,"CID") %>' />
                   <asp:GridView AutoGenerateColumns="false" ShowHeader="false" ID="GridView1" runat="server" GridLines="None" EmptyDataText="Sorry !!! Currently there are no products in this category">
<asp:LinkButton runat="server" Text='<%#Eval("PName") %>' ID="lnkbtnProductName" ></asp:LinkButton></ItemTemplate>

this is how the panes are created

private void fillpane()
        cmd = new SqlCommand( "Select CID,CName from Category", con);
        da = new SqlDataAdapter (cmd);
        ds = new DataSet();
        Accordion1.DataSource = ds.Tables[0].DefaultView;

this is how the gridview get filled

protected void Accordion1_ItemDataBound(object sender, AjaxControlToolkit.AccordionItemEventArgs e)
    if (e.ItemType == AjaxControlToolkit.AccordionItemType.Content)
        cmd = new SqlCommand ("Select PID,PName from Products where PCategoryID='" + ((HiddenField)e.AccordionItem.FindControl("txtCategoryID")).Value + "'", con);
        da = new SqlDataAdapter (cmd);
        ds = new DataSet();
        GridView grd = new GridView();
        grd = (GridView)e.AccordionItem.FindControl("GridView1");
        grd.DataSource = ds;
Posted 12-Feb-12 23:06pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In the onclick event of the button in the gridview you can state:
Button btn = (Button)sender;
GridViewRow row =(GridViewRow)btn.NamingContainer;

all the row.Cells are now available and you can add the neede values to the querystring. The other page can pick the values from querystring.
ujjwal uniyal 13-Feb-12 4:33am
Thanks for the help!!!
it worked..
+5 from me.. :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

<asp:linkbutton runat="server" text="<%#Eval("PName") %>" id="lnkbtnProductName" xmlns:asp="#unknown"></asp:linkbutton>
Replace the above code by the 
<a href="pageName.aspx?ID=<%#DataBinder.Eval(Container.DataItem,"cid")%>">
<%#Eval("PName") %>

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 13 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100