Solved

Edit Gridview

Posted on 2014-01-17
5
428 Views
Last Modified: 2014-01-29
Do I pass parameter the same way if I use a storeprocedure? I am using Gridview to edit and update record.

http://www.aspdotnet-suresh.com/2011/02/normal-0-false-false-false-en-us-x-none.html


UpdateCommand="mystoreprocedure" updatecommandtyep ="StoreProcedure">

<UpdateParameters>

<asp:Parameter Name="UserId" Type= "Int32" />

<asp:Parameter Name="FirstName" Type="String" />

<asp:Parameter Name="LastName" Type="String" />

<asp:Parameter Name="City" Type="String" />

<asp:Parameter Name="Designation" Type="String" />

</UpdateParameters>
0
Comment
Question by:VBdotnet2005
5 Comments
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 39789592
You certainly can.
0
 

Author Comment

by:VBdotnet2005
ID: 39789698
I won't work for me.
0
 

Author Comment

by:VBdotnet2005
ID: 39789713
This is what I have so far. When I click update on Gridview, nothing happens.

<table width="100%">
                                <tr>
                                    <td>
                                        <asp:GridView ID="GridView1" runat="server" AllowPaging="false" AllowSorting="True"
                                            ForeColor="#333333" GridLines="None" AlternatingRowStyle-Wrap="True" AutoGenerateColumns="False"
                                            AutoGenerateEditButton="True" DataKeyNames="id" DataSourceID="SqlDataSource2"
                                            Font-Size="Small" FooterStyle-Font-Size="Medium" PageSize="10" Width="100%">
                                             <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Left" />
                                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                            <Columns>
                                            </Columns>
                                            <Columns>
                                               
                                                <asp:BoundField DataField="id" HeaderText="id" SortExpression="id"
                                                    Visible="false" />
                                                <asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" />
                                                <asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
                                                <asp:BoundField DataField="Phonenum" HeaderText="Phonenum" SortExpression="Phonenum" />
                                                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                                            </Columns>
                                            <FooterStyle />
                                            <AlternatingRowStyle />
                                        </asp:GridView>
                                    </td>
                                </tr>
                            </table>
                       
                            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
                                SelectCommand="select_userinfo"
                                UpdateCommand="update_userinfo" SelectCommandType="StoredProcedure" UpdateCommandType="StoredProcedure">
                                <SelectParameters>
                                    <asp:QueryStringParameter Name="USERID" QueryStringField="userid" Type="String" />
                                </SelectParameters>
                                <UpdateParameters>
                                   
                                    <asp:Parameter Name ="NAME" Type="String" />
                                    <asp:Parameter Name ="username" Type="String" />
                                    <asp:Parameter Name ="Phonenum" Type="String" />
                                    <asp:Parameter Name ="Email" Type="String" />
                                    <asp:Parameter Name ="id" Type="Int64"/>
                                   
                               
                                </UpdateParameters>
                            </asp:SqlDataSource>
                        </ContentTemplate>




alter procedure update_userinfo

@name            varchar(128),
@username      varchar(16),
@phonenum      varchar(24),
@email            varchar(64),
@id      int

as

update mytable set name=@name, username =@username, phonenum=@Phonenum, email=@email, updatebs='Y' where id=@id
0
 
LVL 10

Expert Comment

by:Monica P
ID: 39793690
For Example :

 < asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>"
        SelectCommand= "SELECT email ,phonenum, email  
         FROM [DBO].[UserInformation]"
        UpdateCommand="update_userinfo" UpdateCommandType="StoredProcedure">  
        < UpdateParameters>  
            < asp:Parameter Name="name" Type="String" />  
            < asp:Parameter Name="username" Type="String" />  
            < asp:Parameter Name="phonenum" Type="String" />  
            < asp:Parameter Name="Published" Type="Boolean" />  
            < asp:Parameter Name="email " Type="DateTime" />  
            < asp:Parameter Name="Modify" Type="String" DefaultValue="Update" />  
        < /UpdateParameters>  
    < /asp:SqlDataSource>  

Stored Procedure  definition as mentioned in above...
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39806276
You have to set the parameter values in SqlDataSource.Updating event. See the example on below page (example is for Inserting event but approach would be same for Updating as well)

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasourcecommandeventargs.command(v=vs.110).aspx
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cant save 3D 4 21
VB.NET - Error - Object not set in Module 4 33
Getting error in connectionstring with Excel. 30 33
insert value of checklistbox checked 4 27
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question