Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Ajax
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.
 
<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
 
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
 
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 12-Feb-12 23:06pm
Rate this: bad
good
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.
  Permalink  
Comments
ujjwal uniyal at 13-Feb-12 4:33am
   
Thanks for the help!!!
it worked..
+5 from me.. :)
Rate this: bad
good
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") %>
</a>
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 13 Feb 2012
Copyright © CodeProject, 1999-2014
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