Solved

Edit Gridview

Posted on 2014-01-17
5
432 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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