Solved

Edit Gridview

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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 article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

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