469,282 Members | 2,119 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

GridView Doesnt Update after Deleting a Value

I have a gridview i managed to update using the edit option in the smartmenu. The problem comes when i delete a value or make a value read only.

Say i have a table Employee with the following columns : EmpID, Emp Name, Password, Emp Type.

Now when i remove the value EmpID, the gridview does not update. it just reloads when i hit update but no changes are made.

On the other hand say i make Emp Type as Read only, when i update .. the gridview updates, but the value of Emp Type updates as blank. While editing other values, the value of Emp Type that i made readonly shows correctly. But after i hit update and the values get sent to the DB in access, the field Emp Type updates as blank.

Is there any solution to this ? This is my code for the Employee update page:

Expand|Select|Wrap|Line Numbers
  1. 1    <%@ Page Language="VB" %>
  2. 2    <%@ Import Namespace="System.Data" %>
  3. 3    <%@ Import Namespace="System.Data.OleDb" %>
  4. 4    <script language="VB" runat="server">
  5. 5    
  6. 6    
  7. 7        Protected Sub btlogout_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  8. 8            FormsAuthentication.SignOut()
  9. 9            Response.Redirect("Default.aspx")
  10. 10       End Sub
  11. 11   </script>
  12. 12   
  13. 13   <html xmlns="http://www.w3.org/1999/xhtml" >
  14. 14   <head runat="server">
  15. 15       <title>Origin TimeSheet :: Edit Details</title>
  16. 16       <link rel=stylesheet type="text/css" href="styles.css">
  17. 17   </head>
  18. 18   <body bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0" bgcolor="#EAEAEA">
  19. 19       <form id="form1" runat="server">
  20. 20       <center>
  21. 21   <table border="0" style="border: 2px solid #565656; border-top: 0px" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" height="100%" width="777">
  22. 22       <tr>
  23. 23           <td><!-- logo image --><img src="images/logo.jpg" border="0" width="232" height="106" alt=""><!-- end logo image --><img src="images/header.jpg" border="0" width="279" height="106" alt=""><img src="images/header1.jpg" border="0" width="267" height="106" alt=""></td>
  24. 24       </tr>
  25. 25       <tr>
  26. 26           <td background="images/menu_back.gif" style="height: 42px">
  27. 27               <table border="0" width="100%" cellpadding="0" cellspacing="0">
  28. 28                      <tr><!-- menu starts here -->
  29. 29                          <td width="16%" align="center"><a href="user_welcome.aspx" class="menu">Home</a></td>
  30. 30                          <td><img src="images/menu_d.gif" border="0" width="2" height="29" alt=""></td>
  31. 31                          <td width="16%" align="center"><a href="user_addtime.aspx" class="menu">Add TimeSheet </a></td>
  32. 32                       <td><img src="images/menu_d.gif" border="0" width="2" height="29" alt=""></td>
  33. 33                          <td width="16%" align="center"><a href="user_edittime.aspx" class="menu">Edit TimeSheet </a></td>
  34. 34                       <td><img src="images/menu_d.gif" border="0" width="2" height="29" alt=""></td>
  35. 35                          <td width="16%" align="center"><a href="" class="menu"><span style="color: greenyellow">Edit Details </span></a></td>
  36. 36                       <td><img src="images/menu_d.gif" border="0" width="2" height="29" alt=""></td>
  37. 37                          <td width="16%" align="center"></td>
  38. 38                       <td></td>
  39. 39                       <td width="16%" align="center"></td>
  40. 40                       <td style="padding-right: 80px"></td>
  41. 41                      <!-- menu ends here -->
  42. 42                   </tr>
  43. 43                  </table>                          
  44. 44                                      
  45. 45                                      
  46. 46                                      
  47. 47                                      
  48. 48                                      
  49. 49                                      
  50. 50                                      
  51. 51                                     
  52. 52                                 
  53. 53               <asp:Button ID="Button1" runat="server" Font-Bold="True" ForeColor="Red" OnClick="btlogout_Click"
  54. 54                   Text="Logout" /></td>
  55. 55       </tr>
  56. 56       <tr>
  57. 57           <td height="100%" valign="top" style="text-align: center">
  58. 58               <br />
  59. 59               <span style="font-size: 14pt">
  60. 60                   <br />
  61. 61                   <span style="font-size: 16pt; color: tomato; font-family: Trebuchet MS"><strong>Edit
  62. 62                       your Details<br />
  63. 63                   </strong></span> <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
  64. 64                       DataKeyNames="UserID" DataSourceID="AccessDataSource1" Height="50px" Width="125px">
  65. 65                       <Fields>
  66. 66                           <asp:BoundField DataField="Type" HeaderText="Type" HtmlEncode="False" ReadOnly="True"
  67. 67                               SortExpression="Type" />
  68. 68                           <asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True" SortExpression="UserID" />
  69. 69                           <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
  70. 70                           <asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
  71. 71                           <asp:BoundField DataField="RealName" HeaderText="RealName" SortExpression="RealName" />
  72. 72                           <asp:CommandField ShowEditButton="True" />
  73. 73                       </Fields>
  74. 74                   </asp:DetailsView>
  75. 75                   <asp:AccessDataSource ID="AccessDataSource1" runat="server" ConflictDetection="CompareAllValues"
  76. 76                       DataFile="~/App_Data/origin_timesheet.mdb" DeleteCommand="DELETE FROM [Employee] WHERE [UserID] = ? AND [UserName] = ? AND [Password] = ? AND [RealName] = ? AND [Type] = ?"
  77. 77                       InsertCommand="INSERT INTO [Employee] ([UserID], [UserName], [Password], [RealName], [Type]) VALUES (?, ?, ?, ?, ?)"
  78. 78                       OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Employee] WHERE ([UserName] = ?)"
  79. 79                       UpdateCommand="UPDATE [Employee] SET [UserName] = ?, [Password] = ?, [RealName] = ?, [Type] = ? WHERE [UserID] = ? AND [UserName] = ? AND [Password] = ? AND [RealName] = ? AND [Type] = ?">
  80. 80                       <DeleteParameters>
  81. 81                           <asp:Parameter Name="original_UserID" Type="Int32" />
  82. 82                           <asp:Parameter Name="original_UserName" Type="String" />
  83. 83                           <asp:Parameter Name="original_Password" Type="String" />
  84. 84                           <asp:Parameter Name="original_RealName" Type="String" />
  85. 85                           <asp:Parameter Name="original_Type" Type="String" />
  86. 86                       </DeleteParameters>
  87. 87                       <UpdateParameters>
  88. 88                           <asp:Parameter Name="UserName" Type="String" />
  89. 89                           <asp:Parameter Name="Password" Type="String" />
  90. 90                           <asp:Parameter Name="RealName" Type="String" />
  91. 91                           <asp:Parameter Name="Type" Type="String" />
  92. 92                           <asp:Parameter Name="original_UserID" Type="Int32" />
  93. 93                           <asp:Parameter Name="original_UserName" Type="String" />
  94. 94                           <asp:Parameter Name="original_Password" Type="String" />
  95. 95                           <asp:Parameter Name="original_RealName" Type="String" />
  96. 96                           <asp:Parameter Name="original_Type" Type="String" />
  97. 97                       </UpdateParameters>
  98. 98                       <SelectParameters>
  99. 99                           <asp:SessionParameter Name="UserName" SessionField="S2" Type="String" />
  100. 100                      </SelectParameters>
  101. 101                      <InsertParameters>
  102. 102                          <asp:Parameter Name="UserID" Type="Int32" />
  103. 103                          <asp:Parameter Name="UserName" Type="String" />
  104. 104                          <asp:Parameter Name="Password" Type="String" />
  105. 105                          <asp:Parameter Name="RealName" Type="String" />
  106. 106                          <asp:Parameter Name="Type" Type="String" />
  107. 107                      </InsertParameters>
  108. 108                  </asp:AccessDataSource>
  109. 109                  </span></td>
  110. 110      </tr>
  111. 111      <tr>
  112. 112          <td background="images/footer.gif" height="38">
  113. 113              <table border="0" width="100%" cellpadding="0" cellspacing="0">
  114. 114                     <tr>
  115. 115                         <td width="50%" style="padding: 5px; color: #ffffff">All Rights Reserved 2007 :: Origin</td>
  116. 116                         <td width="50%" style="padding: 5px" align="right">
  117. 117  
  118. 118                     </tr>
  119. 119               </table>   
  120. 120          </td>
  121. 121      </tr>    
  122. 122  </table>
  123. 123  </center>
  124. 124      <div>
  125. 125          <a href="user_welcome.aspx">Home</a><br />
  126. 126          <a href="user_addtime.aspx">Add</a><br />
  127. 127          <a href="user_edittime.aspx">Edit Time</a><br />
  128. 128          <a href="user_myedit.aspx">Edit Deatils</a></div>
  129. 129          <br />
  130. 130          <br />
  131. 131          <asp:Button ID="btlogout" runat="server" OnClick="btlogout_Click" Text="Logout" />
  132. 132      
  133. 133      
  134. 134      </form>
  135. 135  </body>
  136. 136  </html>
Please help me
Thanks and regards in advance.
Jul 9 '07 #1
3 1781
Plater
7,872 Expert 4TB
I am thinking there is some type of "Commit" function that needs to be called for the Deletes to show and that the setting of ReadOnly is calling that function so all your previous changes(like your delete) show through then.
Jul 9 '07 #2
could you please tell me where this "Commit" function is ? is it in the properties of the values in the smart menu or is it something i have to hard code ?

I am guessing that if i select gatagrid1 on one side and rowcommand on the other, something might work out with the right code. But i am sorry, my knowledge of asp is little as i just started learning.

Could be kind enough to guide me as to what to do ?

Thanks for the prompt reply.
Regards.
Jul 9 '07 #3
nmsreddi
366 256MB
Hello

if you want to show the updated data in gridview after deletion or insertion you have to bind the data again after completing particular task,try to bind you will the get silution

Good luck
Jul 10 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Robert Smith jr. | last post: by
5 posts views Thread by Michael | last post: by
1 post views Thread by Mike P | last post: by
4 posts views Thread by =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= | last post: by
2 posts views Thread by Michael | last post: by
reply views Thread by seanmatthewwalsh | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.