sangeetha k

sangeetha k

  • NA
  • 207
  • 51.6k

Correct Me where iam wrong?

Oct 4 2017 3:35 AM
I am trying to display message records unavailable if the particular record is not found with grid header but the problem is I have set the reset button so that it becomes empty but still after clicking the button also it shows the message in the empty data template!!!
 
Please help me with a solution 
 
#Page design code
  1. <div>  
  2. <table class="table">  
  3. <tr>  
  4. <td>  
  5. <asp:TextBox runat="server" ID="txtOrder_id" Width="180px">asp:TextBox>  
  6. td>  
  7. <td>  
  8. <asp:Button runat="server" ID="Btn" Text="Replacement request" OnClick="Btn_Click" Style="height: 26px" />  
  9. td>  
  10. <td>  
  11. <asp:Button runat="server" ID="btnstatus" Text="OrderRequest" OnClick="btnstatus_Click" />  
  12. td>  
  13. <td>  
  14. <asp:Button CssClass="btn" ID="btnreset" runat="server" Text="Reset" OnClick="btnreset_Click" />  
  15. td>  
  16. tr>  
  17. table>  
  18. div>  
  19. <div>  
  20. <table >  
  21. <tr>  
  22. <td>  
  23. <asp:GridView class="grd2" runat="server" ID="grdReplacementRequest" ShowHeaderWhenEmpty="true" AutoGenerateColumns ="False" OnRowEditing="grdReplacementRequest_RowEdit" OnRowUpdating="grdOrderReplacement_RowUpdating" CellPadding="4" ForeColor="#333333" GridLines="None">  
  24. <AlternatingRowStyle BackColor="White" ForeColor="#284775" />  
  25. <Columns>  
  26. <asp:TemplateField HeaderText="Customer_id">  
  27. <ItemTemplate>  
  28. <asp:Label ID="lblcustid" runat"server" Text='<%#Bind("Customer_id") %>'>asp:Label>  
  29. ItemTemplate>  
  30. <FooterTemplate>  
  31. <asp:TextBox ID="txtcustid" runat="server" >asp:TextBox>  
  32. FooterTemplate>  
  33. asp:TemplateField>  
  34. <asp:TemplateField HeaderText="Product_id">  
  35. <ItemTemplate>  
  36. <asp:Label ID="lblpdid" runat"server" Text='<%#Bind("Product_id") %>'>asp:Label>  
  37. ItemTemplate>  
  38. <FooterTemplate>  
  39. <asp:TextBox ID="txtproduct_id" runat="server" >asp:TextBox>  
  40. FooterTemplate>  
  41. asp:TemplateField>  
  42. <asp:TemplateField HeaderText="choice">  
  43. <ItemTemplate>  
  44. <asp:Label ID="lblchoice" runat"server" Text='<%#Bind("choice") %>'>asp:Label>  
  45. ItemTemplate>  
  46. <FooterTemplate>  
  47. <asp:TextBox ID="choice" runat="server" >asp:TextBox>  
  48. FooterTemplate>  
  49. <EditItemTemplate>  
  50. <asp:TextBox ID="txtChoice" runat"server" Text='<%#Bind("choice") %>'>asp:TextBox>  
  51. EditItemTemplate>  
  52. asp:TemplateField>  
  53. <asp:TemplateField HeaderText="Order_id">  
  54. <ItemTemplate>  
  55. <asp:Label ID="lblorderid" runat"server" Text='<%#Bind("order_id") %>'>asp:Label>  
  56. ItemTemplate>  
  57. <FooterTemplate>  
  58. <asp:TextBox ID="txtorderid" runat="server" >asp:TextBox>  
  59. FooterTemplate>  
  60. asp:TemplateField>  
  61. <asp:TemplateField HeaderText="TotalPurchaceValue">  
  62. <ItemTemplate>  
  63. <asp:Label ID="lblAmt" runat"server" Text='<%#Bind("totalamount") %>'>asp:Label>  
  64. ItemTemplate>  
  65. <FooterTemplate>  
  66. <asp:TextBox ID="txtamt" runat="server" >asp:TextBox>  
  67. FooterTemplate>  
  68. asp:TemplateField>  
  69. <asp:TemplateField>  
  70. <EditItemTemplate>  
  71. <asp:Button ID="btnUpdates" runat="server" Text="Update" CommandName="Update" />  
  72. <%-- <asp:LinkButton ID="btnApprove" runat="server" Text="Approve" CommandName="Approved" />  
  73. <asp:LinkButton ID="btnReject" runat="server" Text="Reject" CommandName="Rejected" />--%>  
  74. EditItemTemplate>  
  75. <ItemTemplate>  
  76. <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" />  
  77. ItemTemplate>  
  78. asp:TemplateField>  
  79. Columns>  
  80. <EmptyDataTemplate> No Records Available!! EmptyDataTemplate>  
  81. <EditRowStyle BackColor="#999999" />  
  82. <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />  
  83. <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />  
  84. <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />  
  85. <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />  
  86. asp:GridView>  
  87. td>  
  88. tr>  
  89. table>  
  90. div>  
  91. <div>  
  92. <table>  
  93. <tr>  
  94. <td><asp:GridView CssClass="grd3" runat="server" ID="grdOrderDetails" ShowHeaderWhenEmpty="true" AutoGenerateColumns="False" OnRowCancelingEdit="grdOrderDetails_RowCancelingEdit" OnRowEditing="grdOrderDetails_RowEditing" OnRowUpdating="grdOrderDetails_Rowupdating" ShowFooter="True" CellPadding="4" ForeColor="#333333" GridLines="None">  
  95. <AlternatingRowStyle BackColor="White" ForeColor="#284775" />  
  96. <Columns>  
  97. <asp:TemplateField HeaderText="Customer_id">  
  98. <ItemTemplate>  
  99. <asp:Label ID="Customer_id" runat="server" Text='<%#Bind("Customer_id") %>'>asp:Label>  
  100. ItemTemplate>  
  101. <EditItemTemplate>  
  102. <asp:TextBox ID="txtcustomerid" runat="server" Text='<%#Bind("Customer_id") %>'>asp:TextBox>  
  103. EditItemTemplate>  
  104. asp:TemplateField>  
  105. <asp:TemplateField HeaderText="Product_id">  
  106. <ItemTemplate>  
  107. <asp:Label ID="Product_id" runat="server" Text='<%#Bind("Product_id") %>'>asp:Label>  
  108. ItemTemplate>  
  109. <EditItemTemplate>  
  110. <asp:TextBox ID="txtproductid" runat="server" Text='<%#Bind("Product_id") %>'>asp:TextBox>  
  111. EditItemTemplate>  
  112. asp:TemplateField>  
  113. <asp:TemplateField HeaderText="Category_id">  
  114. <ItemTemplate>  
  115. <asp:Label ID="Category_id" runat="server" Text='<%#Bind("category_id") %>'>asp:Label>  
  116. ItemTemplate>  
  117. <EditItemTemplate>  
  118. <asp:TextBox ID="txtcategoryid" runat="server" Text='<%#Bind("category_id") %>'>asp:TextBox>  
  119. EditItemTemplate>  
  120. asp:TemplateField>  
  121. <asp:TemplateField HeaderText="Order_id">  
  122. <ItemTemplate>  
  123. <asp:Label ID="Order_id" runat="server" Text='<%#Bind("order_id") %>'>asp:Label>  
  124. ItemTemplate>  
  125. <EditItemTemplate>  
  126. <asp:TextBox ID="txtorderid" runat="server" Text='<%#Bind("order_id") %>'>asp:TextBox>  
  127. EditItemTemplate>  
  128. asp:TemplateField>  
  129. <asp:TemplateField HeaderText="TotalPurchaceValue">  
  130. <ItemTemplate>  
  131. <asp:Label ID="Amount" runat="server" Text='<%#Bind("total") %>'>asp:Label>  
  132. ItemTemplate>  
  133. <EditItemTemplate>  
  134. <asp:TextBox ID="txtamt" runat="server" Text='<%#Bind("total") %>'>asp:TextBox>  
  135. EditItemTemplate>  
  136. asp:TemplateField>  
  137. <asp:TemplateField HeaderText="Quantity">  
  138. <ItemTemplate>  
  139. <asp:Label ID="Quantity" runat="server" Text='<%#Bind("orderquantity") %>'>asp:Label>  
  140. ItemTemplate>  
  141. <EditItemTemplate>  
  142. <asp:TextBox ID="quantity" runat="server" Text='<%#Bind("orderquantity") %>'>asp:TextBox>  
  143. EditItemTemplate>  
  144. asp:TemplateField>  
  145. <asp:TemplateField HeaderText="Order_date">  
  146. <ItemTemplate>  
  147. <asp:Label ID="lblOrderdate" runat="server" Text='<%#Bind("Ordered_date") %>'>asp:Label>  
  148. ItemTemplate>  
  149. <EditItemTemplate>  
  150. <asp:TextBox ID="txtorderdate" runat="server" Text='<%#Bind("Ordered_date") %>'>asp:TextBox>  
  151. EditItemTemplate>  
  152. asp:TemplateField>  
  153. <asp:TemplateField>  
  154. <ItemTemplate>  
  155. <asp:Button ID="btn_Edit" runat="server" Text="Edit" CommandName="Edit" />  
  156. ItemTemplate>  
  157. <EditItemTemplate>  
  158. <asp:Button ID="btnUpdate" runat="server" Text="update" CommandName="Update" />  
  159. <asp:Button ID="btnCancel" runat="server" Text="cancel" CommandName="Cancel" />  
  160. EditItemTemplate>  
  161. <FooterTemplate>  
  162. <asp:Button ID="btnAdd" runat="server" Text="add" CommandName="Add" />  
  163. FooterTemplate>  
  164. asp:TemplateField>  
  165. Columns>  
  166. <EmptyDataTemplate>No Records AVailable!!EmptyDataTemplate>  
  167. <EditRowStyle BackColor="#999999" />  
  168. <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />  
  169. <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />  
  170. <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />  
  171. <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />  
  172. <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />  
  173. <SortedAscendingCellStyle BackColor="#E9E7E2" />  
  174. <SortedAscendingHeaderStyle BackColor="#506C8C" />  
  175. <SortedDescendingCellStyle BackColor="#FFFDF8" />  
  176. <SortedDescendingHeaderStyle BackColor="#6F8DAE" />  
  177. asp:GridView>td>  
  178. tr>  
  179. table>  
  180. div>  
#code behind to display message with grid header 
  1. protected void Btn_Click(object sender, EventArgs e)  
  2. {  
  3. try  
  4. {  
  5. if ( grdReplacementRequest.Rows.Count > 0)  
  6. {  
  7. int Order_id = Convert.ToInt32(txtOrder_id.Text);  
  8. bal.getOrderReturnrequest(Order_id);  
  9. grdOrderShow();  
  10. }  
  11. else  
  12. {  
  13. DataTable dt = new DataTable();  
  14. grdReplacementRequest.DataSource = dt;  
  15. grdReplacementRequest.DataBind();  
  16. }  
  17. }  
  18. catch(Exception ex)  
  19. {  
  20. Console.WriteLine("error", ex.Message);  
  21. }  
  22. }  
  23.    
  24. protected void btnstatus_Click(object sender, EventArgs e)  
  25. {  
  26. try  
  27. {  
  28. if (grdOrderDetails.Rows.Count > 0)  
  29. {  
  30. showGrid2();  
  31. }  
  32. else  
  33. {  
  34. DataTable dt = new DataTable();  
  35. grdOrderDetails.DataSource = dt;  
  36. grdOrderDetails.DataBind();  
  37. }  
  38. }  
  39. catch(Exception ex)  
  40. {  
  41. Console.WriteLine(ex.Message);  
  42. }  
  43. }  
  44. protected void btnreset_Click(object sender, EventArgs e)  
  45. {  
  46. txtOrder_id.Text = string.Empty;  
  47. grdOrderDetails.DataSource = null;  
  48. grdOrderDetails.DataBind();  
  49. grdReplacementRequest.DataSource = null;  
  50. grdReplacementRequest.DataBind();  
  51. }  
 

Answers (1)