Solved

Edit Gridview

Posted on 2014-01-17
5
426 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 33

Expert Comment

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now