This article is an extension of my previous article. If you have not taken a look at it kindly click the following link.

http://www.c-sharpcorner.com/UploadFile/17e8f6/nested-repeater-control-in-Asp-Net-4-0/

Well in the preceding article we have nested a repeater control inside one another, but the scenario changes every time, you might want to display data in a more standardized and sophisticated way than just displaying it inside a table control or something like that. Now in this article we will basically learn how to display a GridView control inside a repeater control.

For demonstrating this article we will use a scenario of members placing orders in an online shopping website. Let's say we have a member who place orders for 7 different items respective to the quantity. Now for displaying that member's private data (such as their mailing address, any member instruction given for dispatching data, orderDate, OrderID, Member Name, Membership_ID etc.) along with the products that he/she has added to the cart (details such as productName,Quantities of the product, MRP's of the products etc.) to the administrator of the website. Now from the preceding scenario we will try to create a front end for the administrator who will learn the latest order details placed by the member.

The final output of what we will display will be like the following:

Repeater1.jpg

OK now let's start with the code. For demonstrating the preceding I've used an Oracle Database. The script for it has been included in the article folder.

The following is it:

  1. CREATE TABLE HQM_ADMIN.MEMBERSHIP
  2. (
  3. MEMBERSHIP_ID VARCHAR2(30 BYTE),
  4. MEMBERTITLE VARCHAR2(6 BYTE),
  5. MEMBERNAME VARCHAR2(30 BYTE),
  6. USERNAME VARCHAR2(100 BYTE) NOT NULL,
  7. WORD VARCHAR2(20 BYTE) NOT NULL,
  8. ADDRESS VARCHAR2(500 BYTE)
  9. )
  10. CREATE SEQUENCE HQM_ADMIN.MEMBERSHIP_SEQ
  11. START WITH 5
  12. MAXVALUE 9999999999999999999999999999
  13. MINVALUE 1
  14. NOCYCLE
  15. NOCACHE
  16. NOORDER;
  17. CREATE OR REPLACE PROCEDURE HQM_ADMIN.prc_addmember (
  18. v_title VARCHAR2,
  19. v_name VARCHAR2,
  20. v_address VARCHAR2,
  21. v_username VARCHAR2,
  22. v_word VARCHAR2
  23. )
  24. AS
  25. v_memid VARCHAR (20) := '';
  26. n_memid NUMBER := 0;
  27. BEGIN
  28. n_memid := membership_seq.NEXTVAL;
  29. IF (n_memid < 10)
  30. THEN
  31. v_memid := 'M00' || n_memid;
  32. ELSE
  33. v_memid := 'M0' || n_memid;
  34. END IF;
  35. INSERT INTO membership
  36. (membership_id, membertitle, membername, username, WORD, address)
  37. VALUES (v_memid, v_title, v_name, v_username, v_word,
  38. v_address
  39. );
  40. END;
NOTE: here you could use the Lpad function of Oracle for appending the M00 or M0 with the v_memid variable.

  1. select * from Membership
  2. CREATE TABLE HQM_ADMIN.TBL_MST_ORDERS
  3. (
  4. ORDERID VARCHAR2(30 BYTE),
  5. MEM_ID VARCHAR2(30 BYTE) NOT NULL,
  6. ORDER_VALUE FLOAT(126) NOT NULL,
  7. CUSTOMER_INSTRUCTION VARCHAR2(2000 BYTE),
  8. ORDER_COMMENTS VARCHAR2(2000 BYTE),
  9. ORDER_DATE DATE DEFAULT sysdate,
  10. ORDER_DELIVEREDSTATUS INTEGER DEFAULT 0,
  11. ORDER_DELIVERYDATE DATE DEFAULT null,
  12. ORDER_CANCELLEDFLAG INTEGER DEFAULT 0
  13. )
  14. CREATE SEQUENCE HQM_ADMIN.ORDER_SEQ
  15. START WITH 5
  16. MAXVALUE 9999999999999999999999999999
  17. MINVALUE 1
  18. NOCYCLE
  19. NOCACHE
  20. NOORDER;
  21. CREATE OR REPLACE PROCEDURE HQM_ADMIN.prc_addorder (
  22. v_memberid VARCHAR,
  23. f_ordervalue FLOAT,
  24. v_custinfo VARCHAR
  25. )
  26. AS
  27. n_orderid NUMBER;
  28. v_orderid VARCHAR (30);
  29. BEGIN
  30. n_orderid := order_seq.NEXTVAL;
  31. IF (n_orderid < 10)
  32. THEN
  33. v_orderid := 'O00' || n_orderid;
  34. ELSE
  35. v_orderid := 'O0' || n_orderid;
  36. END IF;
  37. INSERT INTO tbl_mst_orders
  38. (orderid, mem_id, order_value, customer_instruction
  39. )
  40. VALUES (v_orderid, v_memberid, f_ordervalue, v_custinfo
  41. );
  42. END;

NOTE: here you could use the Lpad function of Oracle for appending the O00 or O0 with the v_orderID variable.

  1. CREATE TABLE HQM_ADMIN.TBL_MST_ORDERDESCRIPTION
  2. (
  3. ORDERID VARCHAR2(30 BYTE) NOT NULL,
  4. PRODNAME VARCHAR2(30 BYTE) NOT NULL,
  5. QUANTITY INTEGER NOT NULL,
  6. MRP FLOAT(126) DEFAULT 0,
  7. ITEM_CANCELLEDFLAG INTEGER DEFAULT 0,
  8. ITEM_COMMENTS VARCHAR2(4000 BYTE) DEFAULT 'No Comments'
  9. )
  10. Insert into TBL_MST_ORDERDESCRIPTION
  11. (ORDERID, PRODNAME, QUANTITY, MRP, ITEM_CANCELLEDFLAG, ITEM_COMMENTS)
  12. Values
  13. ('O002', 'Bluetooth Dongle', 1, 300, 0, 'No Comments');
  14. Insert into TBL_MST_ORDERDESCRIPTION
  15. (ORDERID, PRODNAME, QUANTITY, MRP, ITEM_CANCELLEDFLAG, ITEM_COMMENTS)
  16. Values
  17. ('O002', 'Wireless Mouse', 1, 700, 0, 'No Comments');
  18. Insert into TBL_MST_ORDERDESCRIPTION
  19. (ORDERID, PRODNAME, QUANTITY, MRP, ITEM_CANCELLEDFLAG, ITEM_COMMENTS)
  20. Values
  21. ('O002', 'Pen Drive', 2, 300, 0, 'No Comments');
  22. Insert into TBL_MST_ORDERDESCRIPTION
  23. (ORDERID, PRODNAME, QUANTITY, MRP, ITEM_CANCELLEDFLAG, ITEM_COMMENTS)
  24. Values
  25. ('O002', 'HeadSets', 1, 500, 0, 'No Comments');
  26. Insert into TBL_MST_ORDERDESCRIPTION
  27. (ORDERID, PRODNAME, QUANTITY, MRP, ITEM_CANCELLEDFLAG, ITEM_COMMENTS)
  28. Values
  29. ('O002', 'External Hard Drive', 1, 3400, 0, 'No Comments');
  30. COMMIT;
  31. Insert into TBL_MST_ORDERDESCRIPTION
  32. (ORDERID, PRODNAME, QUANTITY, MRP, ITEM_CANCELLEDFLAG, ITEM_COMMENTS)
  33. Values
  34. ('O003', 'LCD Monitor', 4, 3500, 0, 'No Comments');
  35. Insert into TBL_MST_ORDERDESCRIPTION
  36. (ORDERID, PRODNAME, QUANTITY, MRP, ITEM_CANCELLEDFLAG, ITEM_COMMENTS)
  37. Values
  38. ('O003', 'Wireless Mouse', 1, 700, 0, 'No Comments');
  39. Insert into TBL_MST_ORDERDESCRIPTION
  40. (ORDERID, PRODNAME, QUANTITY, MRP, ITEM_CANCELLEDFLAG, ITEM_COMMENTS)
  41. Values
  42. ('O003', 'KeyBoard', 1, 1300, 0, 'No Comments');
  43. Insert into TBL_MST_ORDERDESCRIPTION
  44. (ORDERID, PRODNAME, QUANTITY, MRP, ITEM_CANCELLEDFLAG, ITEM_COMMENTS)
  45. Values
  46. ('O004', 'CPU', 1,8000 , 0, 'No Comments');
  47. Insert into TBL_MST_ORDERDESCRIPTION
  48. (ORDERID, PRODNAME, QUANTITY, MRP, ITEM_CANCELLEDFLAG, ITEM_COMMENTS)
  49. Values
  50. ('O004', 'Wireless Mouse', 1, 700, 0, 'No Comments');
  51. Insert into TBL_MST_ORDERDESCRIPTION
  52. (ORDERID, PRODNAME, QUANTITY, MRP, ITEM_CANCELLEDFLAG, ITEM_COMMENTS)
  53. Values
  54. ('O004', 'KeyBoard', 1, 1300, 0, 'No Comments');
  55. CREATE OR REPLACE PROCEDURE HQM_ADMIN.prc_getallmemberorders (
  56. tempcursor OUT sys_refcursor
  57. )
  58. AS
  59. BEGIN
  60. OPEN tempcursor FOR
  61. SELECT a.orderid, b.membership_id, membertitle, membername, address,
  62. order_value, customer_instruction, prodname, quantity, mrp,
  63. a.order_date, a.order_comments,Address
  64. FROM tbl_mst_orders a INNER JOIN membership b
  65. ON a.mem_id = b.membership_id
  66. INNER JOIN tbl_mst_orderdescription c ON a.orderid = c.orderid
  67. WHERE a.order_cancelledflag = 0
  68. AND a.order_deliveredstatus = 0
  69. AND c.item_cancelledflag = 0;
  70. END;

Our Membership Table contains 3 records like the following with some dummy data:

Repeater2.jpg

Our tbl_mst_Orders table contains 3 records with some dummy data; see:

Repeater3.jpg

Our tbl_mst_orderDescription contains the following dummy data:

Repeater4.jpg

We've used some CSS. The following is the CSS file for that:

  1. body {
  2. /* background: #e5e5e5;*/
  3. background: white;
  4. font-size: .80em;
  5. font-family: "Helvetica Neue", "Lucida Grande", "Segoe UI", Arial, Helvetica, Verdana, sans-serif;
  6. margin: 10px auto;
  7. padding: 0px;
  8. /*color: #696969;*/
  9. color: #3f3f3f;
  10. }
  11. a:visited a:link {
  12. color: #FFFFFF;
  13. }
  14. a:hover {
  15. color: #08D1D5;
  16. text-decoration: none;
  17. }
  18. a:active {
  19. color: #08F990;
  20. }
  21. p {
  22. margin-bottom: 10px;
  23. line-height: 1.6em;
  24. color: black;
  25. }
  26. /* PRIMARY LAYOUT ELEMENTS ----------------------------*/
  27. .page {
  28. width: 1100px;
  29. background-color: #fff;
  30. margin: 20px auto 0px auto;
  31. }
  32. .footer {
  33. color: #4e5766;
  34. padding: 8px 0px 0px 0px;
  35. margin: 0px auto;
  36. width: 1250px;
  37. text-align: center;
  38. line-height: normal;
  39. }
  40. .floatRight {
  41. display: block;
  42. float: right;
  43. vertical-align: top;
  44. width: 220px;
  45. }
  46. .center {
  47. margin-left: 350px;
  48. margin-right: auto;
  49. }
  50. #main {
  51. /*to display the block level elements to the center of the page such as the <p> <div> or <h1> tags*/
  52. margin-left: auto;
  53. margin-right: auto;
  54. width: 960px;
  55. }
  56. /* MISC -------------------------------*/
  57. .clear {
  58. clear: both;
  59. }
  60. .title {
  61. display: block;
  62. float: left;
  63. text-align: left;
  64. width: auto;
  65. }
  66. .title a {
  67. color: #778899;
  68. }
  69. /***********Page Div, TextBox,Dropdownlist,GridView Styling********/
  70. /************Button Styling*************/
  71. .addbtn {
  72. background: url(image/btnbg.png) no-repeat;
  73. padding: 2px 0px;
  74. color: #FFFFFF;
  75. font-weight: bold;
  76. border: 0;
  77. width: 56px;
  78. font-size: 12px;
  79. text-align: center;
  80. cursor: pointer;
  81. }
  82. .addbtn:hover {
  83. background: url(image/btnbg.png) no-repeat bottom;
  84. }
  85. .plainButton {
  86. border: 1px solid #777777;
  87. /*background: #6e9e2d;*/
  88. background: silver;
  89. color: white;
  90. font: bold 11px 'Trebuchet MS';
  91. padding: 4px;
  92. cursor: pointer;
  93. -moz-border-radius: 4px;
  94. -webkit-border-radius: 4px;
  95. }
  96. .blueButton {
  97. background: #5B74A8;
  98. background: -moz-linear-gradient(top, #5B74A8 0%, #5B74A8 100%);
  99. background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #5B74A8), color-stop(100%, #5B74A8));
  100. background: -webkit-linear-gradient(top, #5B74A8 0%, #5B74A8 100%);
  101. background: -o-linear-gradient(top, #5B74A8 0%, #5B74A8 100%);
  102. background: -ms-linear-gradient(top, #5B74A8 0%, #5B74A8 100%);
  103. background: linear-gradient(top, #5B74A8 0%, #5B74A8 100%);
  104. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#5B74A8', endColorstr='#5B74A8', GradientType=0);
  105. padding: 2px 6px;
  106. color: #fff;
  107. font-family: 'Helvetica', sans-serif;
  108. font-size: 11px;
  109. cursor: hand;
  110. border-radius: 0;
  111. -moz-border-radius: 0;
  112. -webkit-border-radius: 0;
  113. border: 1px solid #1A356E;
  114. }
  115. /************End of Button Styling*************/
  116. /********GridView********/
  117. .fortd .grid1 th.txtgreen2 {
  118. color: #009315;
  119. }
  120. .fortd .grid1 th.txtblue2 {
  121. color: #326BD2;
  122. }
  123. .backGround02 {
  124. background: #f9f9f9;
  125. }
  126. .grid1 {
  127. margin: 0;
  128. width: 100%;
  129. height: auto;
  130. border: 1px solid #d4d4d4 !important;
  131. border-bottom: 0px !important;
  132. }
  133. .grid1 th {
  134. background: url(image/thbg.png) repeat-x bottom;
  135. font-size: 11px;
  136. font-weight: bold;
  137. color: #333;
  138. padding: 10px 10px;
  139. border: 0px !important;
  140. }
  141. .grid1 td {
  142. border: 0px !important;
  143. border-bottom: 1px solid #d4d4d4 !important;
  144. color: #666;
  145. padding: 6px 10px 6px 10px;
  146. text-align: center;
  147. vertical-align: middle;
  148. }
  149. .grid1 td a {
  150. font-size: 11px;
  151. font-weight: bold;
  152. color: #3c94dc;
  153. text-decoration: underline;
  154. }
  155. .grid1 td a:hover {
  156. color: #333;
  157. }
  158. /***************End of GridView**************/
  159. /***********Tabular Div Styling**************/
  160. .parentDiv {
  161. width: 100%;
  162. float: left;
  163. }
  164. .gqmn03 {
  165. float: left;
  166. width: 100%;
  167. padding-bottom: 3px;
  168. display: none;
  169. }
  170. .divDivider {
  171. float: left;
  172. width: 100%;
  173. padding-bottom: 3px;
  174. margin-bottom: 0px;
  175. }
  176. .gqmn01sub {
  177. float: left;
  178. width: 100%;
  179. padding-bottom: 7px;
  180. }
  181. .gqmn01_lt {
  182. float: left;
  183. font-size: 11px;
  184. padding: 3px 10px 0 8px;
  185. padding-bottom: 10px;
  186. }
  187. .gqmn01_lt label {
  188. padding: 0 10px 0 0;
  189. }
  190. .gqmn01_rt {
  191. float: left;
  192. }
  193. .additionalInfo .gqmn01sub {
  194. width: 470px;
  195. float: left;
  196. padding: 0 0 0 0;
  197. }
  198. .subElements {
  199. width: 550px;
  200. float: left;
  201. padding: 0 0 0 0;
  202. }
  203. .gqmn03sub {
  204. width: 100%;
  205. float: left;
  206. padding: 0 0 0 0;
  207. }
  208. .additionalInfo .subText {
  209. width: 100%;
  210. padding-bottom: 7px;
  211. }
  212. .additionalInfo .subTextLabel {
  213. width: 190px;
  214. }
  215. .additionalInfo .txtbg02 {
  216. float: left;
  217. }
  218. .biggerTxt {
  219. width: 100%;
  220. padding-bottom: 7px;
  221. height: 30px;
  222. }
  223. .subText {
  224. float: left;
  225. }
  226. .subText label b {
  227. color: #CC0000;
  228. font-size: 10px;
  229. font-weight: normal;
  230. }
  231. .subTextLabel {
  232. width: 128px;
  233. padding-left: 8px;
  234. font-weight: normal;
  235. float: left;
  236. text-align: right;
  237. color: #666666;
  238. padding: 4px 8px 0 0;
  239. }
  240. /******End Of Tabular Div Styling*************/
  241. /************Form Elements TextBox Styles*************/
  242. .txtArea {
  243. border-radius: 5px;
  244. }
  245. .txtbg3 {
  246. border: 1px solid #c6c6c6;
  247. color: #333333;
  248. font-size: 11px;
  249. font-family: Arial, Helvetica, sans-serif;
  250. padding: 2px;
  251. width: 186px;
  252. float: left;
  253. border-radius: 5px;
  254. }
  255. .txtbg02 {
  256. width: 217px;
  257. height: 23px;
  258. border: 0;
  259. padding: 0 5px;
  260. line-height: 21px;
  261. border-radius: 5px;
  262. }
  263. /******End Of TextBox Styling***********/
  264. /***End of Page Div, TextBox,Dropdownlist,GridView Styling*****/
  265. /*************Width Section*************/
  266. .w100 {
  267. width: 100%;
  268. height: 35px;
  269. }
  270. .w100>p {
  271. width: 30%;
  272. float: left;
  273. text-align: center;
  274. }
  275. .w90 {
  276. width: 90%;
  277. }
  278. .w80 {
  279. width: 80%;
  280. }
  281. .w60 {
  282. width: 60%;
  283. }
  284. .w45 {
  285. width: 45%;
  286. }
  287. .w30 {
  288. width: 30%;
  289. }
  290. .w10 {
  291. width: 10%;
  292. }
  293. /*************Box Styling************/
  294. .h2txt {
  295. font-family: Arial, Helvetica, sans-serif;
  296. color: #333333;
  297. font-size: 13px;
  298. font-weight: bold;
  299. }
  300. .h2txt img {
  301. vertical-align: middle;
  302. cursor: pointer;
  303. float: left;
  304. margin-right: 8px;
  305. }
  306. .box1 {
  307. width: 1050px;
  308. padding: 5px 15px;
  309. background-color: Silver;
  310. color: white;
  311. margin-bottom: 20px;
  312. margin-top: 10px;
  313. border-radius: 5px;
  314. }
  315. .box2 {
  316. width: 790px;
  317. padding: 4px 15px;
  318. margin: 4px auto auto 5px;
  319. height: 20px;
  320. background-color: silver;
  321. /*#ED8029*/
  322. color: white;
  323. border-radius: 5px;
  324. }
  325. .transitionColor {
  326. -webkit-transition: background-color 5s;
  327. -moz-transition: background-color 5s;
  328. -o-transition: background-color 5s;
  329. -ms-transition: background-color 5s;
  330. transition: background-color 5s;
  331. background-color: #A7B526;
  332. }
  333. /**************End of Box Styling**********/
  334. /*************Height Section***************/
  335. .h100 {
  336. height: 100%;
  337. }
  338. .h50 {
  339. height: 50%;
  340. }
  341. .h30 {
  342. height: 30%;
  343. }
  344. /**************End of Height Section********************/
  345. /*******************Margin Section********************/
  346. .mt30 {
  347. margin-top: 30px;
  348. }
  349. .mt5 {
  350. margin-top: 5px;
  351. }
  352. .mtp5 {
  353. margin-top: 5%;
  354. }
  355. .w100 p {
  356. float: left;
  357. width: 30%;
  358. text-align: center;
  359. }
  360. .mtp10 {
  361. margin-top: 10%;
  362. }
  363. .mtp30 {
  364. margin-top: 30%;
  365. }
  366. .mlf5 {
  367. margin-left: 5%;
  368. }
  369. .mlf10 {
  370. margin-left: 10%;
  371. }
  372. .mlf25 {
  373. margin-left: 25%;
  374. }
  375. .left5 {
  376. float: left;
  377. margin-left: 5%;
  378. }
  379. /************End Of Margin Section****************/
  380. .amount {
  381. font-family: Arial, Helvetica, sans-serif;
  382. font-size: 20px;
  383. font-weight: normal;
  384. color: #006BB2;
  385. padding: 0px;
  386. }
  387. .amount A {
  388. color: #006BB2;
  389. text-decoration: none;
  390. }
  391. .PRICE A:hover {
  392. color: #006BB2;
  393. text-decoration: underline;
  394. }
  395. .amount2 {
  396. font-family: Arial, Helvetica, sans-serif;
  397. font-size: 12px;
  398. font-weight: normal;
  399. color: #1F1F99;
  400. padding: 0px;
  401. padding-right: 5px;
  402. vertical-align: bottom;
  403. margin-right: 5px;
  404. font-weight: bold;
  405. }
  406. .amount2 A {
  407. color: #1F1F99;
  408. text-decoration: none;
  409. }
  410. .amount2 A:hover {
  411. color: #1F1F99;
  412. text-decoration: underline;
  413. }

The following is the Markup file for it:

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title></title>
  6. <link rel="Stylesheet" type="text/css" href="Style.css" />
  7. <script type="text/javascript">
  8. function confirmCancellOrder(chkObj) {
  9. var checkBoxObj = chkObj;
  10. if (checkBoxObj.checked == true) {
  11. var x = confirm("Do you want to Cancelled Order?");
  12. if (x == true) {
  13. __doPostBack('<%=udpOrderDescription.ClientID %>', "");
  14. }
  15. else
  16. return false;
  17. }
  18. else {
  19. chkObj.checked = false;
  20. return false;
  21. }
  22. }
  23. function changeDeliveredQuantity(txtObj) {
  24. var textBoxObj = txtObj;
  25. if (textBoxObj.value == "") {
  26. textBoxObj.value = 0;
  27. alert('Enter a value');
  28. __doPostBack('<%=udpOrderDescription.ClientID %>', "");
  29. }
  30. else if (!isNaN(textBoxObj.value)) {
  31. __doPostBack('<%=udpOrderDescription.ClientID %>', "");
  32. }
  33. else {
  34. textBoxObj.value = 0;
  35. alert('Only Numeric values are allowed');
  36. }
  37. }
  38. </script>
  39. </head>
  40. <body>
  41. <form id="form1" runat="server">
  42. <div class="page">
  43. <asp:ScriptManager ID="ScriptManager1" runat="server">
  44. </asp:ScriptManager>
  45. <asp:UpdatePanel ID="udpOrderDescription" runat="server">
  46. <ContentTemplate>
  47. <asp:Repeater ID="parentRepeater" runat="server" OnItemDataBound="parentRepeater_ItemDataBound">
  48. <HeaderTemplate>
  49. <div class="parentDiv additionalInfo">
  50. <h2 class="h2txt box1">
  51. <asp:Label ID="Label1" Font-Bold="true" runat="server" Text="Online Computer Store"></asp:Label>
  52. </h2>
  53. </HeaderTemplate>
  54. <ItemTemplate>
  55. <div class="divDivider" id="divDetail1">
  56. <div class="subElements">
  57. <div class="subText">
  58. <label class="subTextLabel">
  59. Order ID:
  60. </label>
  61. <asp:Label ID="lblOrderID" runat="server" CssClass="txtbg3" Font-Bold="true" Text='<%#Eval("OrderID") %>'></asp:Label>
  62. </div>
  63. <div class="subText">
  64. <label class="subTextLabel">
  65. Member ID:
  66. </label>
  67. <asp:Label ID="lblMemberID" Font-Bold="true" runat="server" CssClass="txtbg3" Text='<%#Eval("Membership_ID") %>'></asp:Label>
  68. </div>
  69. <div class="subText">
  70. <label class="subTextLabel">
  71. Address:
  72. </label>
  73. <asp:TextBox ID="txtAddress" Text='<%#Eval("Address") %>' runat="server" Enabled="false"
  74. CssClass="txtArea" TextMode="MultiLine" Rows="2" Columns="35"></asp:TextBox>
  75. </div>
  76. <div class="subText">
  77. <label class="subTextLabel">
  78. Order Comments:
  79. </label>
  80. <asp:TextBox ID="txtOrderComments" Text='<%#Eval("order_comments") %>' runat="server"
  81. CssClass="txtArea" TextMode="MultiLine" Rows="2" Columns="35"></asp:TextBox>
  82. </div>
  83. </div>
  84. <div class="subElements">
  85. <div class="subText">
  86. <label class="subTextLabel">
  87. Order Date:
  88. </label>
  89. <asp:Label ID="lblOrderDate" runat="server" CssClass="txtbg3" Font-Bold="true" Text='<%#Convert.ToDateTime(Eval("Order_Date")).ToString("dd MMM yyyy") %>'></asp:Label>
  90. </div>
  91. <div class="subText">
  92. <label class="subTextLabel">
  93. Name:
  94. </label>
  95. <asp:Label ID="lblName" runat="server" CssClass="txtbg3" Font-Bold="true" Text='<%#Eval("MemberName") %>'></asp:Label>
  96. </div>
  97. <div class="subText">
  98. <label class="subTextLabel">
  99. Customer Instructions:
  100. </label>
  101. <asp:TextBox ID="txtCustInstruction" Enabled="false" runat="server" TextMode="MultiLine"
  102. CssClass="txtArea" Rows="2" Columns="35" Text='<%#Eval("Customer_Instruction") %>'></asp:TextBox>
  103. </div>
  104. <div class="subText">
  105. <label class="subTextLabel">
  106. Order Cancelled:<asp:HiddenField ID="hdnOrderID" runat="server" Value='<%#Eval("OrderID") %>' />
  107. </label>
  108. <asp:CheckBox ID="chkOrderCancelled" runat="server" AutoPostBack="true" onClick="javascript:return confirmCancellOrder(this);" />
  109. </div>
  110. </div>
  111. </div>
  112. <div class="divDivider" id="divDetail2">
  113. <asp:GridView ID="gvwProductDescription" runat="server" AutoGenerateColumns="false"
  114. CssClass="grid1" AlternatingRowStyle-CssClass="backGround02" ShowFooter="true"
  115. OnRowDataBound="gvwProductDescription_RowDataBound">
  116. <Columns>
  117. <asp:TemplateField HeaderText="Sr.No">
  118. <ItemTemplate>
  119. <asp:Label ID="lblSrNo" runat="server" Text='<%#Container.DataItemIndex + 1%>'></asp:Label>
  120. <asp:HiddenField ID="hdnGridOrderId" runat="server" Value='<%#Bind("OrderID") %>' />
  121. </ItemTemplate>
  122. </asp:TemplateField>
  123. <asp:BoundField DataField="ProdName" HeaderText="Product ID" />
  124. <asp:TemplateField HeaderText="Quantity">
  125. <ItemTemplate>
  126. <asp:Label ID="lblQuantity" runat="server" Text='<%#Bind("Quantity") %>'></asp:Label>
  127. </ItemTemplate>
  128. <FooterTemplate>
  129. <asp:Label ID="lblLabel" runat="server" Text="<b>Total Bill:</b>"></asp:Label>
  130. </FooterTemplate>
  131. </asp:TemplateField>
  132. <asp:BoundField DataField="MRP" HeaderText="MRP" />
  133. <asp:TemplateField HeaderText="Total">
  134. <ItemTemplate>
  135. <asp:Label ID="lblTotal" CssClass="amount2" runat="server" Text='<%#Bind("Total") %>'></asp:Label>
  136. </ItemTemplate>
  137. <FooterTemplate>
  138. <asp:Label ID="lblGrandTotal" CssClass="amount" runat="server"></asp:Label>
  139. <asp:Button ID="btnDelivered" runat="server" Text="Deliver" CommandName="Delivered"
  140. CssClass="addbtn" />
  141. </FooterTemplate>
  142. </asp:TemplateField>
  143. </Columns>
  144. </asp:GridView>
  145. </div>
  146. <div class="divDivider" id="divDetail3">
  147. <hr style="width: 100%; height: 10px; background-color: #0e0e6c; border: 2px solid silver;" />
  148. </div>
  149. </ItemTemplate>
  150. <FooterTemplate>
  151. <div class="divDivider">
  152. <asp:Button ID="btnFirst" runat="server" Text="<<" CssClass="left5" OnClick="CommonButton_Click" />
  153. <asp:Button ID="btnPrevious" runat="server" Text="<" CssClass="left5" OnClick="CommonButton_Click" />
  154. <asp:Button ID="btnNext" runat="server" Text=">" CssClass="left5" OnClick="CommonButton_Click" />
  155. <asp:Button ID="btnLast" runat="server" Text=">>" CssClass="left5" OnClick="CommonButton_Click" />
  156. </div>
  157. </div>
  158. </FooterTemplate>
  159. </asp:Repeater>
  160. </ContentTemplate>
  161. </asp:UpdatePanel>
  162. </div>
  163. </form>
  164. </body>
  165. </html>

The following is the source code for it:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Data.OracleClient;
  9. public partial class _Default : System.Web.UI.Page
  10. {
  11. OracleConnection con;
  12. OracleDataAdapter da;
  13. DataSet ds;
  14. DataTable dtRepeaterTable;
  15. OracleCommand cmd;
  16. PagedDataSource pageDataSource = new PagedDataSource();
  17. private const string _dbCon = "DATA SOURCE=DHQMDB;WORD=hqm321;PERSIST SECURITY INFO=True;USER ID=HQM_ADMIN";
  18. public int CurrentPage
  19. {
  20. get
  21. {
  22. // look for current page in ViewState
  23. object o = this.ViewState["_CurrentPage"];
  24. if (o == null)
  25. return 0; // default to showing the first page
  26. else
  27. return (int)o;
  28. }
  29. set
  30. {
  31. this.ViewState["_CurrentPage"] = value;
  32. }
  33. }
  34. protected void Page_Load(object sender, EventArgs e)
  35. {
  36. if (!IsPostBack)
  37. LoadAllCurrentOrders();
  38. }
  39. /// <summary>
  40. /// This function is used for loading all the current and active order which
  41. /// needs to be delivered
  42. /// </summary>
  43. private void LoadAllCurrentOrders()
  44. {
  45. if (ViewState["repeaterData"] == null)
  46. {
  47. con = new OracleConnection(_dbCon);
  48. da = new OracleDataAdapter("prc_getallmemberorders", con);
  49. da.SelectCommand.CommandType = CommandType.StoredProcedure;
  50. OracleParameter outPara = new OracleParameter("tempcursor", OracleType.Cursor);
  51. outPara.Direction = ParameterDirection.Output;
  52. da.SelectCommand.Parameters.Add(outPara);
  53. ds = new DataSet();
  54. da.Fill(ds);
  55. if (ds.Tables[0].Rows.Count > 0)
  56. {
  57. ViewState["currentOrders"] = ds;
  58. dtRepeaterTable = new DataTable();
  59. string[] parentCols = { "OrderId", "Membership_Id", "Order_Date", "MemberName", "Customer_Instruction", "OrderValue", "Order_Comments", "Address" };
  60. foreach (string str in parentCols)
  61. {
  62. dtRepeaterTable.Columns.Add(str);
  63. }
  64. var varHeadingTable = ds.Tables[0].AsEnumerable().GroupBy(x => x["OrderID"].ToString()).Select(grp => grp.First()).Distinct();
  65. foreach (var res in varHeadingTable)
  66. {
  67. DataRow dr = dtRepeaterTable.NewRow();
  68. dr[0] = res["OrderID"];
  69. dr[1] = res["Membership_ID"];
  70. dr[2] = res["Order_Date"];
  71. dr[3] = res["MemberTitle"] + " " + res["MemberName"];
  72. dr[4] = res["Customer_Instruction"];
  73. dr[5] = res["Order_Value"];
  74. dr[6] = res["order_comments"];
  75. dr[7] = res["Address"];
  76. dtRepeaterTable.Rows.Add(dr);
  77. }
  78. ViewState["repeaterData"] = dtRepeaterTable;
  79. }
  80. }
  81. else
  82. dtRepeaterTable = (DataTable)ViewState["repeaterData"];
  83. if (dtRepeaterTable.Rows.Count > 0)
  84. {
  85. pageDataSource.DataSource = dtRepeaterTable.DefaultView;
  86. pageDataSource.PageSize = 2;
  87. pageDataSource.AllowPaging = true;
  88. pageDataSource.CurrentPageIndex = CurrentPage;
  89. ViewState["totalCount"] = pageDataSource.PageCount;
  90. parentRepeater.DataSource = pageDataSource;
  91. parentRepeater.DataBind();
  92. RepeaterItem footerRepeaterItem = (RepeaterItem)parentRepeater.Controls[parentRepeater.Controls.Count - 1];
  93. Button btnFirst = (Button)footerRepeaterItem.FindControl("btnFirst");
  94. Button btnPrevious = (Button)footerRepeaterItem.FindControl("btnPrevious");
  95. Button btnNext = (Button)footerRepeaterItem.FindControl("btnNext");
  96. Button btnLast = (Button)footerRepeaterItem.FindControl("btnLast");
  97. btnFirst.Enabled = !pageDataSource.IsFirstPage;
  98. btnPrevious.Enabled = !pageDataSource.IsFirstPage;
  99. btnNext.Enabled = !pageDataSource.IsLastPage;
  100. btnLast.Enabled = !pageDataSource.IsLastPage;
  101. }
  102. }
  103. private DataTable LoadOrderDetails(string orderID)
  104. {
  105. ds = (DataSet)ViewState["currentOrders"];
  106. DataTable dtGridTable = new DataTable();
  107. var varGridTable = ds.Tables[0].AsEnumerable().Where(x => x["OrderID"].ToString() == orderID).Select(d => d);
  108. string[] gridCols = { "OrderID", "ProdName", "Quantity", "MRP", "Total" };
  109. foreach (string str in gridCols)
  110. dtGridTable.Columns.Add(str);
  111. foreach (var res in varGridTable)
  112. {
  113. DataRow dr = dtGridTable.NewRow();
  114. dr[0] = res["OrderID"];
  115. dr[1] = res["ProdName"];
  116. dr[2] = res["Quantity"];
  117. dr[3] = res["MRP"];
  118. dr[4] = float.Parse(res["Quantity"].ToString()) * float.Parse(res["MRP"].ToString());
  119. dtGridTable.Rows.Add(dr);
  120. }
  121. return dtGridTable;
  122. }
  123. protected void parentRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
  124. {
  125. if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  126. {
  127. Label lblOrderID = (Label)e.Item.FindControl("lblOrderID");
  128. GridView gvwProducts = (GridView)e.Item.FindControl("gvwProductDescription");
  129. DataTable dt = LoadOrderDetails(lblOrderID.Text);
  130. ViewState["gridTable"] = dt;
  131. gvwProducts.DataSource = dt;
  132. gvwProducts.DataBind();
  133. }
  134. }
  135. protected void gvwProductDescription_RowDataBound(object sender, GridViewRowEventArgs e)
  136. {
  137. if (e.Row.RowType == DataControlRowType.Footer)
  138. {
  139. GridView gvwProduct = (GridView)sender;
  140. Label lblGrandTotal = (Label)e.Row.FindControl("lblGrandTotal"); ;
  141. if (ViewState["gridTable"] != null)
  142. {
  143. DataTable dt = (DataTable)ViewState["gridTable"];
  144. float total = dt.AsEnumerable().Sum(x => float.Parse(x["Total"].ToString()));
  145. lblGrandTotal.Text = total.ToString();
  146. }
  147. }
  148. }
  149. #region Pagination Events
  150. protected void CommonButton_Click(object sender, EventArgs e)
  151. {
  152. Button b = (Button)sender;
  153. if (b.ID == "btnFirst")
  154. {
  155. CurrentPage = 0;
  156. LoadAllCurrentOrders();
  157. }
  158. else if (b.ID == "btnPrevious")
  159. {
  160. CurrentPage -= 1;
  161. LoadAllCurrentOrders();
  162. }
  163. else if (b.ID == "btnNext")
  164. {
  165. CurrentPage += 1;
  166. LoadAllCurrentOrders();
  167. }
  168. else if (b.ID == "btnLast")
  169. {
  170. CurrentPage = Convert.ToInt32(ViewState["totalCount"].ToString()) - 1;
  171. LoadAllCurrentOrders();
  172. }
  173. }
  174. #endregion
  175. }

Here I've used ViewState but of course there are multiple ways to maintain the state of the application. You could go for session or any way you prefer the most. This is just a dummy application for demonstration purpose.

Hope you liked the article.