Nested Gridview & paging!

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 36
Reputation: Alexpap is an unknown quantity at this point 
Solved Threads: 0
Alexpap Alexpap is offline Offline
Light Poster

Nested Gridview & paging!

 
0
  #1
Oct 4th, 2009
Greetings members,
i would like you to help me with a problem that i have. I have a gridview and in each row of the gridview there is a nested gridview. What i want i to insert paging functionality, to the nested Gridview control.

Thanks in advance,
Alexander
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: Nested Gridview & paging!

 
0
  #2
Oct 5th, 2009
Can you post your code
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 36
Reputation: Alexpap is an unknown quantity at this point 
Solved Threads: 0
Alexpap Alexpap is offline Offline
Light Poster

Re: Nested Gridview & paging!

 
0
  #3
Oct 5th, 2009
here is the .aspx code that i have fore the gridview:

  1. <asp:GridView ID="ItemsGrid" runat="server" AutoGenerateColumns="False"
  2. CellPadding="4" ForeColor="#333333" GridLines="None"
  3. onrowdatabound="ItemsGrid_RowDataBound" Width="466px">
  4. <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  5. <Columns>
  6. <asp:TemplateField HeaderText="Expand Details">
  7. <ItemTemplate>
  8. <asp:HyperLink ID="ExpandCollapse" runat="server" Text="+"></asp:HyperLink>
  9. </ItemTemplate>
  10. </asp:TemplateField>
  11. <asp:TemplateField HeaderText="Items">
  12. <ItemTemplate>
  13. <asp:Label ID="lblStatTitle" runat="server"></asp:Label>
  14. <asp:Panel ID="ItemDetails" runat="server" Style="display:none">
  15. <asp:GridView ID="SubGridView" runat="server" AutoGenerateColumns="true" AllowPaging="true" PageSize="5" OnPageIndexChanging="SubGrid_PageIndexChanging">
  16. <Columns>
  17. </Columns>
  18. </asp:GridView>
  19. </asp:Panel>
  20. </ItemTemplate>
  21. </asp:TemplateField>
  22. </Columns>
  23. <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  24. <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
  25. <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
  26. <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  27. <EditRowStyle BackColor="#999999" />
  28. <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
  29. </asp:GridView>

what i would like to do is to add the paging functionality to the 'Subgrid' Gridview.
Last edited by Alexpap; Oct 5th, 2009 at 4:52 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training
 
0
  #4
Oct 6th, 2009
On ASPX

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title>Untitled Page</title>
  6. <script type="text/javascript" language="javascript" src="JScript.js"></script>
  7.  
  8. </head>
  9. <body>
  10. <form id="form1" runat="server">
  11. <div>
  12.  
  13. <asp:SqlDataSource ID="SqlDataSource1" runat="server"
  14. ConnectionString="<%$ ConnectionStrings:LocalConnectionString %>"
  15. SelectCommand="SELECT * FROM [tablename]"></asp:SqlDataSource>
  16. <br />
  17. <br />
  18. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  19. <br />
  20.  
  21. <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
  22. AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" PageSize="20" OnRowDataBound="GridView1_RowDataBound" CellPadding="4"
  23. Forecolor="#333333" GridLines="None">
  24. <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  25. <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  26. <Columns>
  27. <asp:TemplateField>
  28. <ItemTemplate>
  29. <a href="javascript:ShowChildGrid('div<%# Eval("ID") %>');">
  30. <img id="imgdiv<%# Eval("ID") %>"
  31. alt="Click to show/hide orders"
  32. border="0"
  33. src="Images/arrowright.jpg"/>
  34. </a>
  35. </ItemTemplate>
  36. </asp:TemplateField>
  37.  
  38. <asp:BoundField DataField="a" HeaderText="a"
  39. SortExpression="a" />
  40. <asp:BoundField DataField="b" HeaderText="b"
  41. SortExpression="b" />
  42. <asp:BoundField DataField="c" HeaderText="c"
  43. SortExpression="c" />
  44.  
  45. <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True"
  46. SortExpression="ID" />
  47. <asp:TemplateField>
  48. <ItemTemplate>
  49. </td>
  50. </tr>
  51. <tr>
  52. <td colspan="100%">
  53. <div id="div<%# Eval("ID") %>" style="display:none;position:relative;left:25px;" >
  54. <asp:GridView ID="GridView2" runat="server"
  55. AllowPaging="true"
  56. AutoGenerateColumns="false"
  57. DataKeyNames="CustomerId"
  58. Width="80%"
  59. CellPadding="4"
  60. ForeColor="#333333"
  61. GridLines="None"
  62. PageSize="5"
  63. OnPageIndexChanging="GridView2_PageIndexChanging">
  64. <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  65. <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  66. <Columns>
  67. <asp:BoundField DataField="Alias" HeaderText="CustomerName"
  68. SortExpression="Alias" />
  69. <asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" />
  70. <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
  71. <asp:BoundField DataField="Fee" HeaderText="Fee"
  72. SortExpression="Fee" />
  73. </Columns>
  74. </asp:GridView>
  75. </div>
  76. </td>
  77. </tr>
  78. </ItemTemplate>
  79. </asp:TemplateField>
  80.  
  81.  
  82.  
  83. </Columns>
  84. </asp:GridView>
  85. <br />
  86. <br />
  87. <br />
  88.  
  89. </div>
  90. </form>
  91. </body>
  92. </html>

On ASPX.CS

  1. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
  2. if (e.Row.RowType == DataControlRowType.DataRow) {
  3. BindGridToDS(GridView1.DataKeys[e.Row.RowIndex].Value.ToString(), (GridView)e.Row.FindControl("GridView2"));
  4. }
  5. }
  6.  
  7. protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e) {
  8. GridView gvwChild = ((GridView)sender);
  9. GridViewRow gvRowParent = ((GridView)sender).Parent.Parent as GridViewRow;
  10.  
  11. gvwChild.PageIndex = e.NewPageIndex;
  12. BindGridToDS(GridView1.DataKeys[gvRowParent.RowIndex].Value.ToString(), gvwChild);
  13.  
  14. //show the div again after postback
  15. string strDIVID = "div" + GridView1.DataKeys[gvRowParent.RowIndex].Value.ToString();
  16. string cScript = "<script type=\"text/javascript\">ShowChildGrid('" + strDIVID + "');</script>";
  17. ClientScript.RegisterStartupScript(typeof(Page), "clientscript", cScript);
  18. }
  19.  
  20. private void BindGridToDS(string strCustomerID, GridView gv) {
  21. SqlDataSource dbSrc = new SqlDataSource();
  22. dbSrc.ConnectionString = ConfigurationManager.ConnectionStrings["LocalConnectionString"].ConnectionString;
  23. dbSrc.SelectCommand = "SELECT * FROM Customer";// WHERE ProviderID = '" + strCustomerID + "' ORDER BY created";
  24. gv.DataSource = dbSrc;
  25. gv.DataBind();
  26. }

On the JS File JScript.js
  1. function ShowChildGrid(obj)
  2. {
  3. var div = document.getElementById(obj);
  4. var img = document.getElementById('img' + obj);
  5. var theFlag = div.style.display == "none";
  6. div.style.display = (theFlag) ? "inline" : "none";
  7. img.src = (theFlag) ? "Images/arrowdown.jpeg" : "Images/arrowright.jpeg";
  8. }

Dont forget to add two images arrowright.jpeg and arrowdown.jpeg to an Images folder in your Solution.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC