Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hello!!!

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.

XML
<asp:Accordion ID="Accordion1" runat="server"
        TransitionDuration="300" FadeTransitions="true"
            ContentCssClass="accordion-content" HeaderCssClass="accordion-header"
            HeaderSelectedCssClass="accordion-selected"
            onitemdatabound="Accordion1_ItemDataBound" Width="100%"
            onitemcommand="Accordion1_ItemCommand">
           <HeaderTemplate>
               <asp:Label runat="server" ID="lblCategory" Text='<%# Eval("CName") %>'></asp:Label>

           </HeaderTemplate>
           <ContentTemplate>

               <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">
        <Columns>
        <asp:TemplateField>
        <ItemTemplate>
<asp:LinkButton runat="server" Text='<%#Eval("PName") %>' ID="lnkbtnProductName" ></asp:LinkButton></ItemTemplate>
        </asp:TemplateField>
        </Columns>
        </asp:GridView>

           </ContentTemplate>
        </asp:Accordion>



this is how the panes are created

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



this is how the gridview get filled

C#
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();
        da.Fill(ds);
        GridView grd = new GridView();
        grd = (GridView)e.AccordionItem.FindControl("GridView1");
        grd.DataSource = ds;
        grd.DataBind();
    }
}
Posted

In the onclick event of the button in the gridview you can state:
C#
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.
 
Share this answer
 
Comments
ujjwal uniyal 13-Feb-12 4:33am    
Thanks for the help!!!
it worked..
+5 from me.. :)
<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") %>
</a>
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900