| | |
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:
Solved Threads: 0
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:-
Also I am not really sure if my objectdatasource id="objdsColleagueDetails
UpdateParameters
DeleteParameters
Parameters are correct.
My web service is as follows.
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
thanks for your help.
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:-
ASP.NET Syntax (Toggle Plain Text)
Protected Sub gvwColleagueDetails_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvwColleagueDetails.RowUpdating End Sub
Also I am not really sure if my objectdatasource id="objdsColleagueDetails
UpdateParameters
DeleteParameters
Parameters are correct.
My web service is as follows.
ASP.NET Syntax (Toggle Plain Text)
WAB_DataAccessWS.vb Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Data Imports System.IO <WebService(Namespace:="WAB_DataAccessWS")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Public Class WAB_DataAccessWS Inherits System.Web.Services.WebService <WebMethod()> _ Public Function GenericQuery(ByVal strConn As String, ByVal strQuery As String) As DataSet Return WAB_DataAccess.GenericQuery(strConn, strQuery) End Function 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
asp.net Syntax (Toggle Plain Text)
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:HiddenField ID="hdnMainConnStr" runat="server" /> <asp:HiddenField ID="hdnQueryDepartmentDetails" runat="server" /> <asp:HiddenField ID="hdnQueryColleagueDetails" runat="server" /> <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=""> <tr> <td align="center" style="height: 19px"><asp:label id="lblMsg" runat="server" cssclass="" enableviewstate="false">Please Select Your Department</asp:label></td> </tr> </table> <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=""> <tr> <td align="center" style="height: 65px"> <asp:DropDownList ID="ddlDepartment" runat="server" CssClass="" DataSourceID="objDepartmentDetails" DataValueField="DepartmentName" AutoPostBack="true"> </asp:DropDownList> <asp:ObjectDataSource ID="objDepartmentDetails" runat="server" SelectMethod="GenericQuery" TypeName="WAB_DataAccessWS.WAB_DataAccessWS"> <SelectParameters> <asp:ControlParameter ControlID="hdnMainConnStr" Name="strConn" PropertyName="Value" Type="String"/> <asp:Parameter defaultvalue="exec p_DepartmentDetails" name="strQuery" type="String" /> </SelectParameters> </asp:ObjectDataSource> </td> </tr> </table> <table id="tblPages" width="100%" border="0" cellpadding="0" cellspacing="0" class=""> <tr> <td align="left"> <br /> Rows per page: <asp:textbox id="txtRowsPerPage" runat="server" cssclass="" autopostback="true" columns="4" maxlength="4" tabindex="5" /> </td> </tr> </table> <br /> <table id="tblColleagueDetailsData" width="100%" border="0" cellpadding="0" cellspacing="0" class=""> <tr> <td align="center"> <asp:GridView ID="gvwColleagueDetails" runat="server" EmptyDataText="No colleague records were found." datasourceid="objdsColleagueDetails" cellpadding="0" borderwidth="1px" bordercolor="Black" borderstyle="Solid" width="100%" allowsorting="True" allowpaging="True" autogeneratecolumns="False" > <pagersettings position="top" mode="NumericFirstLast" /> <pagerstyle horizontalalign="Left" /> <Columns> <asp:boundfield headertext="ColleagueName" datafield="ColleagueName" sortexpression="ColleagueName" readonly="True" > <itemstyle width="5%" /> </asp:boundfield> <asp:boundfield headertext="Mobile" datafield="Mobile" sortexpression="Mobile" readonly="True" > <itemstyle width="5%" /> </asp:boundfield> <asp:boundfield headertext="Extension" datafield="Extension" sortexpression="Extension" readonly="True" > <itemstyle width="5%" /> </asp:boundfield> <asp:CommandField ButtonType="Button" HeaderText="Add Remove Colleague" ShowDeleteButton="True" ShowEditButton="True" /> </Columns> </asp:GridView> <asp:objectdatasource id="objdsColleagueDetails" runat="server" selectmethod="GenericQuery" typename="WAB_DataAccessWS.WAB_DataAccessWS"> <UpdateParameters> <asp:Parameter Name="id" Type="Int32" /> <asp:Parameter Name="firstname" Type="String" /> <asp:Parameter Name="middlename" Type="String" /> <asp:Parameter Name="lastname" Type="String" /> <asp:Parameter Name="Mobile" Type="String" /> <asp:Parameter Name="Extension" Type="String" /> </UpdateParameters> <DeleteParameters> <asp:Parameter Name="id" Type="Int32" /> <asp:Parameter Name="firstname" Type="String" /> <asp:Parameter Name="middlename" Type="String" /> <asp:Parameter Name="lastname" Type="String" /> <asp:Parameter Name="Mobile" Type="String" /> <asp:Parameter Name="Extension" Type="String" /> </DeleteParameters> <selectparameters> <asp:controlparameter controlid="hdnMainConnStr" defaultvalue="" name="strConn" propertyname="Value" type="String" /> <asp:controlparameter controlid="hdnQueryColleagueDetails" name="strQuery" propertyname="Value" type="String" /> </selectparameters> </asp:objectdatasource> <br /> <br /> <br /> </td> </tr> </table> <table id="tblAddDesc" width="100%" border="0" cellpadding="0" cellspacing="0" class=""> <tr> <td align="center"><asp:label id="Label1" runat="server" cssclass="" enableviewstate="false">Add Colleague Details</asp:label></td> </tr> </table> <table id="tblAddColleague" width="100%" border="0" cellpadding="0" cellspacing="0" class=""> <tr> <td align="right"> <asp:DropDownList ID="ddlAddColleague" runat="server" CssClass="" DataSourceID="objdsAddColleague" DataValueField="ColleagueName" AutoPostBack="true"> </asp:DropDownList><asp:ObjectDataSource ID="objdsAddColleague" runat="server" SelectMethod="GenericQuery" TypeName="WAB_DataAccessWS.WAB_DataAccessWS"> <SelectParameters> <asp:ControlParameter ControlID="hdnMainConnStr" Name="strConn" PropertyName="Value" Type="String"/> <asp:Parameter defaultvalue="exec p_AddColleague" name="strQuery" type="String" /> </SelectParameters> </asp:ObjectDataSource> </td> <td align="left"> <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> </tr> </table> <br /> <br /> <br /> <br /> <br /> <table id="tblLinks" width="100%" border="0" cellpadding="0" cellspacing="0" class=""> <tr> <td align="center"> <a href="Default.aspx">Holiday Entitlemant</a> </td> <td align="center"> <a href="Default.aspx">Whereabouts Summary</a> </td> <td align="center"> <a href="Default.aspx">Whereabouts Update</a> </td> <td align="center"> <a href="Default.aspx">Rota</a> </td> <td align="center"> <a href="Default.aspx">Meetings</a> </td> </tr> </table> </div> </form> </body> </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.
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
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
•
•
Join Date: Sep 2007
Posts: 4
Reputation:
Solved Threads: 0
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
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
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: Report Viewer doesnt work on web application
- Next Thread: Date problem server-side
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax appliances asp asp.net bc30451 beginner bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn cac checkbox child class click compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownmenu dynamic edit embeddingactivexcontrol feedback fileuploader findcontrol flash flv forms gridview homeedition hosting iframe iis javascript jquery list menu mono mssql multistepregistration nameisnotdeclared novell objects order problem ratings relationaldatabases rotatepage save search security serializesmo.table sessionvariables silverlight smartcard sql ssl suse textbox tracking treeview typeof unauthorized validatedate validation vb.net video virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt webdevelopment wizard xml





