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:-

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.

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

<%@ 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.

Recommended Answers

All 6 Replies

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

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

Thanks for that just what i needed.

thanks for that

no probs anytime

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.