Click here to Skip to main content
13,193,048 members (80,166 online)
Rate this:
Please Sign up or sign in to vote.
I having this problem, and I seriously cannot figure out what is wrong with the code.. I had researched for weeks yet the same problem keep persist.

I have a webform called UserProfile.aspx. After user logged-in, they can view and edit their particulars at UserProfile. I used a SqlDataSource and was binding the data to a DetailsView. In the details view, it retrieved data from 3 tables and the selecting query works fine and could display data successfully.

However, when I update the information and hit on the Update button in the DetailsView, it page post back after the update button is pressed with no change to it.

Following is the code which I get the current logged-in user(inside UserProfile.aspx):

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
         ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"

           SelectCommand="SELECT aspnet_Membership.Email, Details.CustName, Details.CustNum, Details.CustRole, Details.CustStatus, Details.PName, Details.PEmail, Details.PRole, Details.WedDate, aspnet_Users.UserName FROM Details INNER JOIN aspnet_Membership ON Details.UserId = aspnet_Membership.UserId INNER JOIN aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId WHERE Details.UserId = @UserId"

             UpdateCommand="UPDATE Details SET CustName = @CustName, CustNum = @CustNum, CustRole = @CustRole, CustStatus = @CustStatus, PName = @PName, PEmail = @PEmail, PRole = @PRole, WedDate = @WedDate WHERE [UserId] = @UserId">
               <asp:Parameter Name="UserId" type="String" />
              <asp:Parameter Name="UserId" type="String" />
               <asp:Parameter Name="CustName" type="String"  />
               <asp:Parameter Name="CustNum" type="String" />
               <asp:Parameter Name="CustRole" type="String" />
               <asp:Parameter Name="CustStatus" type="String" />
               <asp:Parameter Name="PName" type="String" />
               <asp:Parameter Name="PEmail" type="String"  />
               <asp:Parameter Name="PRole" type="String"  />
               <asp:Parameter Name="WedDate" type="String" />

       <br />
       <asp:DetailsView ID="DetailsView1" runat="server"

               <asp:BoundField DataField="UserName" HeaderText="UserName"
                   SortExpression="UserName" ReadOnly="True" />
               <asp:BoundField DataField="Email" HeaderText="Email"
                   SortExpression="Email" />


               <asp:BoundField DataField="CustName" HeaderText="CustName"
                   SortExpression="CustName" />
               <asp:BoundField DataField="CustNum" HeaderText="CustNum"
                   SortExpression="CustNum" />
               <asp:BoundField DataField="CustRole" HeaderText="CustRole"
                   SortExpression="CustRole" />
               <asp:BoundField DataField="CustStatus" HeaderText="CustStatus"
                   SortExpression="CustStatus" />
               <asp:BoundField DataField="PName" HeaderText="PName"
                   SortExpression="PName" />
               <asp:BoundField DataField="PEmail" HeaderText="PEmail"
                   SortExpression="PEmail" />
               <asp:BoundField DataField="PRole" HeaderText="PRole"
                   SortExpression="PRole" />
               <asp:BoundField DataField="WedDate" HeaderText="WedDate"
                   SortExpression="WedDate" />
               <asp:CommandField ShowEditButton="True" />
               <br />

This is the code in my UserProfile.aspx.cs :

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        // Get a reference to the currently logged on user
        MembershipUser currentUser = Membership.GetUser();
        // Determine the currently logged on user's UserId value
        // Assign the currently logged on user's UserId to the @UserId parameter
        //access the parameter value using e.Command.Parameters
        //programmatically set the @UserId:
        e.Command.Parameters["@UserId"].Value = currentUser.ProviderUserKey.ToString();
    //When I run the webform, the UserId of the current logged-in user had displayed, 
    // the @UserId was not empty. 
Posted 4-Jul-12 20:07pm
A_K_ 5-Jul-12 2:39am
It it changing in database?
junetanweiting 5-Jul-12 9:26am
Hi. Nope, it is not changing..
junetanweiting 5-Jul-12 9:29am
If i take out the WHERE clause from the update query, the detailsview can update sucessfully, however the new updated value will update all the records in that table instead of just that particular record.. if i add in the WHERE clause, the problem are just like above explained post.. "page post back after the update button is pressed with no change to it"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171017.2 | Last Updated 5 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100