Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 31st, 2007, 10:01 AM
Authorized User
 
Join Date: Sep 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieving a parameter from a deleting datagrid

Hi everyone,

I am trying to delete a gridview's row(the gridview is filled with all users that belongs to a given relationship). I'm using my own delete stored procedure which needs 2 parameters @REL_ID and @USER_ID. The first one its easy for me to retrieve because it is stored in a control. But what I don't know how to retrieve is the @USER_ID parameter because it is stored in the gridview's USER_ID cell from the row I am deleting.

I hope you can understand my problem.
Thank you for your patience and best regards!
 
Old October 31st, 2007, 10:33 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Are we talking Winforms DataGridView or ASP.Net GridView?

With WinForms its of the format:

DataGridView.CurrentRow.Cells[i].Value

With ASP.Net its slightly more complicated as the following returns a TableCell which will have one or more web controls in it (usually a couple of literals and a label).

The following should get its contents assuming its just a label:

GridView.SelectedRow.Cells[i].Text

Does this help?

/- Sam Judson : Wrox Technical Editor -/
 
Old October 31st, 2007, 10:49 AM
Authorized User
 
Join Date: Sep 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Sam in advance.
I am using ASP.NET GridView.
Here is what I am exactly doing:
Grid view:
<asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource3" AutoGenerateColumns="False">
                    <Columns>
                        <asp:CommandField ShowDeleteButton="True" />
                        <asp:BoundField DataField="USER_ID" HeaderText="USER_ID" InsertVisible="False" ReadOnly="True"
                            SortExpression="USER_ID" />
                        <asp:BoundField DataField="USER_FIRSTNAME" HeaderText="USER_FIRSTNAME" SortExpression="USER_FIRSTNAME" />
                        <asp:BoundField DataField="USER_LASTNAME" HeaderText="USER_LASTNAME" SortExpression="USER_LASTNAME" />
                        <asp:BoundField DataField="WORKREL_USER_ID" HeaderText="WORKREL_USER_ID" InsertVisible="False"
                            ReadOnly="True" SortExpression="WORKREL_USER_ID" />
                    </Columns>
                </asp:GridView>

User Firstname, Lastname and Id are part of the tblUSERS then WORKREL_USER_ID column is part of tblWORKRELATIONSHIP_USER.

Here is the dataSource that I am using for this grid:
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:itworks %>"
        SelectCommand="uspEmpSelectedinWorkRel" SelectCommandType="StoredProcedure"
        DeleteCommand="uspEmpinWorkRelDelete" DeleteCommandType="StoredProcedure">
        <DeleteParameters>
            <asp:Parameter Direction="ReturnValue" Name="RETURN_VALUE" />
            <asp:Parameter Name="WORKREL_USER_ID" Type="Int32" />
        </DeleteParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlWorkRel" DefaultValue="1" Name="WORKREL_ID" PropertyName="SelectedValue"
                Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

When I want to delete one row it says that WORKREL_ID parameter has not been specified.

Here is the storede procedure I am using to fill GridView2:

SELECT tblUSERS.USER_ID,USER_FIRSTNAME, USER_LASTNAME, tblWORKRELATIONSHIP_USER.WORKREL_USER_ID FROM tblUSERS
    INNER JOIN tblWORKRELATIONSHIP_USER ON
    tblUSERS.USER_ID = tblWORKRELATIONSHIP_USER.USER_ID
    WHERE tblWORKRELATIONSHIP_USER.WORKREL_ID = @WORKREL_ID

And here is the delete stored procedure:

    DELETE FROM tblWORKRELATIONSHIP_USER WHERE WORKREL_USER_ID = @WORKREL_USER_ID

I really thank you in advance and I hope you can help me with this problem
 
Old November 1st, 2007, 12:08 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Annoyingly I'm not able to get this working myself, so I can't be much help I'm afraid.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding and Deleting info from Datagrid toddw607 ASP.NET 2.0 Basics 2 April 20th, 2007 10:40 AM
deleting row in a datagrid * nightmare :-( chrismogz ADO.NET 4 October 30th, 2006 05:47 PM
deleting in datagrid derekl ASP.NET 1.0 and 1.1 Professional 2 January 26th, 2006 05:21 AM
Retrieving value from Datagrid texbox eli2003 ASP.NET 1.0 and 1.1 Basics 2 September 3rd, 2003 03:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.