How do i get a datagrid to update & delete rows.

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

Join Date: Sep 2007
Posts: 4
Reputation: ANGanley is an unknown quantity at this point 
Solved Threads: 0
ANGanley ANGanley is offline Offline
Newbie Poster

How do i get a datagrid to update & delete rows.

 
0
  #1
Jan 25th, 2009
I have a web application using vb.net.

What I need to do is get my datagrid to update and delete rows in a datagrid.

I have a grid view that calls a web service, passing in a query string.

The problem I am having is, I am not sure what code I need to write to update and delte items in the grid view.

I will be using stored procedures to update & delete the information.

do i use:-
  1. Protected Sub gvwColleagueDetails_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvwColleagueDetails.RowUpdating
  2.  
  3.  
  4. End Sub

Also I am not really sure if my objectdatasource id="objdsColleagueDetails

UpdateParameters
DeleteParameters

Parameters are correct.

My web service is as follows.

  1. WAB_DataAccessWS.vb
  2. Imports System.Web
  3. Imports System.Web.Services
  4. Imports System.Web.Services.Protocols
  5. Imports System.Data
  6. Imports System.IO
  7.  
  8. <WebService(Namespace:="WAB_DataAccessWS")> _
  9. <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
  10. <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
  11. Public Class WAB_DataAccessWS
  12. Inherits System.Web.Services.WebService
  13.  
  14. <WebMethod()> _
  15. Public Function GenericQuery(ByVal strConn As String, ByVal strQuery As String) As DataSet
  16. Return WAB_DataAccess.GenericQuery(strConn, strQuery)
  17. End Function
  18.  
  19. End Class

My database.

Colleaguedetails Table
Column Name Datatype
PK ColleagueID nvarchar(50)
Lastname nvarchar(50)
Mobile nvarchar(25)
Extension nvarchar(25)

DepartmentDetails
Column Name Datatype
PK DepartmentID int
DepartmentName nvarchar(50)

ColleagueDepartment
Column Name Datatype
CollDepID int
ColleagueID int
DepartmentID int

My web page

  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head id="Head1" runat="server">
  7. <title>Untitled Page</title>
  8. </head>
  9. <body>
  10. <form id="form1" runat="server">
  11. <div>
  12. <asp:HiddenField ID="hdnMainConnStr" runat="server" />
  13. <asp:HiddenField ID="hdnQueryDepartmentDetails" runat="server" />
  14. <asp:HiddenField ID="hdnQueryColleagueDetails" runat="server" />
  15.  
  16. <table id="tblDepartment" width="100%" border="0" style="border-bottom-width:1px; border-bottom-color:Black; border-bottom-style:solid" cellpadding="0" cellspacing="0" class="">
  17.  
  18. <tr>
  19. <td align="center" style="height: 19px"><asp:label id="lblMsg" runat="server" cssclass="" enableviewstate="false">Please Select Your Department</asp:label></td>
  20.  
  21. </tr>
  22. </table>
  23. <table id="tblDepartmentSelection" width="100%" border="0" style="border-bottom-width:1px; border-bottom-color:Black; border-bottom-style:solid" cellpadding="0" cellspacing="0" class="">
  24.  
  25. <tr>
  26. <td align="center" style="height: 65px">
  27. <asp:DropDownList ID="ddlDepartment" runat="server" CssClass="" DataSourceID="objDepartmentDetails" DataValueField="DepartmentName" AutoPostBack="true">
  28.  
  29. </asp:DropDownList>
  30. <asp:ObjectDataSource ID="objDepartmentDetails" runat="server" SelectMethod="GenericQuery" TypeName="WAB_DataAccessWS.WAB_DataAccessWS">
  31.  
  32. <SelectParameters>
  33. <asp:ControlParameter ControlID="hdnMainConnStr" Name="strConn"
  34. PropertyName="Value" Type="String"/>
  35. <asp:Parameter defaultvalue="exec p_DepartmentDetails" name="strQuery" type="String" />
  36. </SelectParameters>
  37. </asp:ObjectDataSource>
  38. </td>
  39. </tr>
  40. </table>
  41. <table id="tblPages" width="100%" border="0" cellpadding="0" cellspacing="0" class="">
  42. <tr>
  43. <td align="left">
  44. <br />
  45. Rows per page:
  46. <asp:textbox id="txtRowsPerPage" runat="server" cssclass="" autopostback="true" columns="4" maxlength="4" tabindex="5" />
  47. </td>
  48. </tr>
  49. </table>
  50. <br />
  51. <table id="tblColleagueDetailsData" width="100%" border="0" cellpadding="0" cellspacing="0" class="">
  52. <tr>
  53. <td align="center">
  54. <asp:GridView ID="gvwColleagueDetails" runat="server"
  55. EmptyDataText="No colleague records were found."
  56. datasourceid="objdsColleagueDetails" cellpadding="0" borderwidth="1px"
  57. bordercolor="Black" borderstyle="Solid" width="100%" allowsorting="True"
  58. allowpaging="True" autogeneratecolumns="False" >
  59.  
  60. <pagersettings position="top" mode="NumericFirstLast" />
  61. <pagerstyle horizontalalign="Left" />
  62. <Columns>
  63. <asp:boundfield headertext="ColleagueName" datafield="ColleagueName" sortexpression="ColleagueName" readonly="True" >
  64.  
  65. <itemstyle width="5%" />
  66. </asp:boundfield>
  67. <asp:boundfield headertext="Mobile" datafield="Mobile" sortexpression="Mobile" readonly="True" >
  68.  
  69. <itemstyle width="5%" />
  70. </asp:boundfield>
  71. <asp:boundfield headertext="Extension" datafield="Extension" sortexpression="Extension" readonly="True" >
  72.  
  73. <itemstyle width="5%" />
  74. </asp:boundfield>
  75. <asp:CommandField ButtonType="Button" HeaderText="Add Remove Colleague"
  76. ShowDeleteButton="True" ShowEditButton="True" />
  77. </Columns>
  78. </asp:GridView>
  79. <asp:objectdatasource id="objdsColleagueDetails" runat="server" selectmethod="GenericQuery" typename="WAB_DataAccessWS.WAB_DataAccessWS">
  80. <UpdateParameters>
  81. <asp:Parameter Name="id" Type="Int32" />
  82. <asp:Parameter Name="firstname" Type="String" />
  83. <asp:Parameter Name="middlename" Type="String" />
  84. <asp:Parameter Name="lastname" Type="String" />
  85. <asp:Parameter Name="Mobile" Type="String" />
  86. <asp:Parameter Name="Extension" Type="String" />
  87. </UpdateParameters>
  88. <DeleteParameters>
  89. <asp:Parameter Name="id" Type="Int32" />
  90. <asp:Parameter Name="firstname" Type="String" />
  91. <asp:Parameter Name="middlename" Type="String" />
  92. <asp:Parameter Name="lastname" Type="String" />
  93. <asp:Parameter Name="Mobile" Type="String" />
  94. <asp:Parameter Name="Extension" Type="String" />
  95. </DeleteParameters>
  96. <selectparameters>
  97. <asp:controlparameter controlid="hdnMainConnStr" defaultvalue="" name="strConn" propertyname="Value" type="String" />
  98. <asp:controlparameter controlid="hdnQueryColleagueDetails" name="strQuery" propertyname="Value" type="String" />
  99. </selectparameters>
  100. </asp:objectdatasource>
  101. <br />
  102. <br />
  103. <br />
  104. </td>
  105. </tr>
  106. </table>
  107. <table id="tblAddDesc" width="100%" border="0" cellpadding="0" cellspacing="0" class="">
  108. <tr>
  109. <td align="center"><asp:label id="Label1" runat="server" cssclass="" enableviewstate="false">Add Colleague Details</asp:label></td>
  110.  
  111. </tr>
  112. </table>
  113. <table id="tblAddColleague" width="100%" border="0" cellpadding="0" cellspacing="0" class="">
  114. <tr>
  115. <td align="right">
  116. <asp:DropDownList ID="ddlAddColleague" runat="server" CssClass="" DataSourceID="objdsAddColleague" DataValueField="ColleagueName" AutoPostBack="true">
  117.  
  118. </asp:DropDownList><asp:ObjectDataSource ID="objdsAddColleague" runat="server" SelectMethod="GenericQuery" TypeName="WAB_DataAccessWS.WAB_DataAccessWS">
  119.  
  120. <SelectParameters>
  121. <asp:ControlParameter ControlID="hdnMainConnStr" Name="strConn"
  122. PropertyName="Value" Type="String"/>
  123. <asp:Parameter defaultvalue="exec p_AddColleague" name="strQuery" type="String" />
  124. </SelectParameters>
  125. </asp:ObjectDataSource>
  126. </td>
  127. <td align="left">
  128.  
  129. <asp:button id="btnAdd" cssclass="" runat="server" text="Add Colleague" tooltip="Add Colleague" onclientclick="return confirmAction('Are you sure you want to Add Colleague"/></td>
  130.  
  131. </tr>
  132. </table>
  133. <br />
  134. <br />
  135. <br />
  136. <br />
  137. <br />
  138. <table id="tblLinks" width="100%" border="0" cellpadding="0" cellspacing="0" class="">
  139. <tr>
  140. <td align="center">
  141. <a href="Default.aspx">Holiday Entitlemant</a>
  142. </td>
  143. <td align="center">
  144. <a href="Default.aspx">Whereabouts Summary</a>
  145. </td>
  146. <td align="center">
  147. <a href="Default.aspx">Whereabouts Update</a>
  148. </td>
  149. <td align="center">
  150. <a href="Default.aspx">Rota</a>
  151. </td>
  152. <td align="center">
  153. <a href="Default.aspx">Meetings</a>
  154. </td>
  155. </tr>
  156. </table>
  157. </div>
  158. </form>
  159. </body>
  160. </html>


thanks for your help.
Last edited by peter_budo; Jan 27th, 2009 at 7:34 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 130
Reputation: sedgey is on a distinguished road 
Solved Threads: 8
sedgey's Avatar
sedgey sedgey is offline Offline
Junior Poster

Re: How do i get a datagrid to update & delete rows.

 
0
  #2
Jan 26th, 2009
2 approaches
1. Add the logic for delete and update to your webservice and specify these via the datasource wizard
2. Add the update delete logic to your page class and handle the update and delete events of your datagrid in the page class
David Ridgway: so little daylight, too much caffeine
MCSD MCAD MCSE
http://web2asp.net
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 4
Reputation: ANGanley is an unknown quantity at this point 
Solved Threads: 0
ANGanley ANGanley is offline Offline
Newbie Poster

Re: How do i get a datagrid to update & delete rows.

 
0
  #3
Jan 26th, 2009
Thanks for that, my boss would prefer the second approach.

If i pass my connection string through a web service, have you any code examples of how to update the rows in the datagrid.

the table i want to update is Colleaguedetails Table. i'll be using an update stored procedure.

would i need something like add(parameter)@firstname
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 130
Reputation: sedgey is on a distinguished road 
Solved Threads: 8
sedgey's Avatar
sedgey sedgey is offline Offline
Junior Poster

Re: How do i get a datagrid to update & delete rows.

 
0
  #4
Jan 26th, 2009
David Ridgway: so little daylight, too much caffeine
MCSD MCAD MCSE
http://web2asp.net
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 4
Reputation: ANGanley is an unknown quantity at this point 
Solved Threads: 0
ANGanley ANGanley is offline Offline
Newbie Poster

Re: How do i get a datagrid to update & delete rows.

 
0
  #5
Jan 26th, 2009
Thanks for that just what i needed.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 4
Reputation: ANGanley is an unknown quantity at this point 
Solved Threads: 0
ANGanley ANGanley is offline Offline
Newbie Poster

Re: How do i get a datagrid to update & delete rows.

 
0
  #6
Jan 27th, 2009
thanks for that
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 130
Reputation: sedgey is on a distinguished road 
Solved Threads: 8
sedgey's Avatar
sedgey sedgey is offline Offline
Junior Poster

Re: How do i get a datagrid to update & delete rows.

 
0
  #7
Jan 27th, 2009
no probs anytime
David Ridgway: so little daylight, too much caffeine
MCSD MCAD MCSE
http://web2asp.net
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC