Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Edit Gridview

Posted on 2014-01-17
5
Medium Priority
?
437 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

877 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